public class MapMatchingMain {
public static void main(String[] args) {
...
MapMatching mapMatching = new MapMatching(hopper, opts);
JavaRDD<String> matchedTraces = traceData.map(
new Function<String, String>() {
@Override
public String call(String s) throws Exception {
return singleTraceMatch(getTraceFromString(s), mapMatching));
}
}
);
}
}
当我在mapMatching
方法中实例化main()
实例时,我将得到错误消息
线程“ main” org.apache.spark.SparkException中的异常:任务不可序列化
public class MapMatchingMain {
private static MapMatching mapMatching = new MapMatching();
public static void main(String[] args) {
...
JavaRDD<String> matchedTraces = traceData.map(
new Function<String, String>() {
@Override
public String call(String s) throws Exception {
return singleTraceMatch(getTraceFromString(s));
}
}
);
}
}
如果我将mapMatching
实例实例化为类MapMatchingMain
的静态成员变量,则没有问题。
我已经阅读了一些答案,说静态字段值未序列化。那么如何将其分配给每个工人呢?