ClassNotFoundException:流类校验和不匹配

时间:2014-06-28 02:23:25

标签: java gridgain

我的远程(Linux)和本地(windows)节点都使用相同的jdk版本1.7.0_45和gridgain 6.0.3并启用了对等类加载。但我得到了以下内容:

Caused by: java.lang.ClassNotFoundException: Optimized stream class checksum mismatch (is same version of marshalled class present on all nodes?) [expected=-3449, actual=7739, cls=class java.io.FileDescriptor]
    at org.gridgain.grid.marshaller.optimized.GridOptimizedClassResolver.readClass(GridOptimizedClassResolver.java:345)

本地节点控制台有日志:

visor> [20:50:12] Local node's library list differs from remote node's
[20:50:12] <commons-lang-2.6.jar> vs. <not jar or zip file>
[20:50:12] <guava-14.0.1.jar> vs. <guava-15.0.jar>
[20:50:12] <javax.servlet-api-3.0.1.jar> vs. <servlet-api-2.4.jar>
[20:50:12] <jcommander-1.30.jar> vs. <jcommander-1.27.jar>
[20:50:12] <log4j-1.2.16.jar> vs. <log4j.jar>
[20:50:12]

代码

public final class GG_HelloWorld {

    public static class GridCmd extends Command<GridEvt> {


        @Override
        protected void executeImpl() throws CommandException, InterruptedException {

            final GridConfiguration config = getEvent().getConfig();


            // task
            GridComputeTask<String, Integer> task = new GridComputeTaskSplitAdapter<String, Integer>() {

                @NotNull
                @Override
                protected Collection<? extends GridComputeJob> split(int gridSize,
                        @NotNull String arg) {

                    Collection<GridComputeJob> jobs = new LinkedList<>();

                    for (final String word : arg.split(" ")) {

                        jobs.add(new GridComputeJobAdapter() {

                            @Nullable
                            @Override
                            public Object execute() {

                                X.println(">>>");
                                X.println(">>> Printing '" + word
                                          + "' on this node from grid job.");
                                X.println(">>>");


                                // Return number of letters in the word.
                                return word.length();
                            }

                        });
                    }

                    return jobs;
                }

                @Nullable
                @Override
                public Integer reduce(@NotNull List<GridComputeJobResult> results) {
                    return results.size() - 1 + F.sumInt(F.<Integer>jobResults(results));
                }

            };

            try (Grid g = G.start(config)) {

                GridComputeTaskFuture<Integer> fut = g.compute().execute(task, "Hello Grid Enabled World!");


                // Wait for task completion.
                int phraseLen = fut.get();

                X.println(">>>");
                X.println(">>> Finished executing Grid \"Hello World\" example with custom task.");
                X.println(">>> Total number of characters in the phrase is '" + phraseLen + "'.");
                X.println(">>> Check all nodes for output (this node is also part of the grid).");
                X.println(">>>");

            } catch (GridException e) {
                throw new CommandException(e);
            }
        }
    }            

}

文件相关代码仅由主节点调用。

2 个答案:

答案 0 :(得分:1)

您似乎正在尝试(有意或无意)通过网络发送java.io.FileDescriptor。我现在无法确认这一点,但我认为这个类可能是特定于平台的,因此校验和不匹配。

另一方面,反序列化的文件描述符无论如何都不会在远程计算机上有效,因为它包含操作系统文件描述符/句柄。我认为这里的解决方案只是为了确保java.io.FileDescriptor的实例不会发送到远程节点。

如果要发送匿名计算闭包,请尝试将其设置为静态并将所有必需参数作为构造函数参数传递。这样,您将确保java编译器不会向您的类捕获额外的局部变量。

答案 1 :(得分:1)

此外,如果要将FileDescriptor保留在要发送的其中一个类中,则可以将其声明为transient,并在访问时重新初始化远程节点。