java + spark: org.apache.spark.SparkException: Trabalho cancelado: Tarefa não serializável: java.io.NotSerializableException

Eu sou novo no spark, e estava tentando executar o exemplo JavaSparkPi.java, ele funciona bem, mas como tenho que usá-lo em outro java s copio todas as coisas de main para um método na classe e tento chamar o método principal, diz

org.apache.spark.SparkException: Trabalho cancelado: Tarefa não serializável: java.io.NotSerializableException

o código fica assim:

public class JavaSparkPi {

public void cal(){
    JavaSparkContext jsc = new JavaSparkContext("local", "JavaLogQuery");
    int slices = 2;
    int n = 100000 * slices;

    List<Integer> l = new ArrayList<Integer>(n);
    for (int i = 0; i < n; i++) {
        l.add(i);
    }

    JavaRDD<Integer> dataSet = jsc.parallelize(l, slices);

    System.out.println("count is: "+ dataSet.count());
    dataSet.foreach(new VoidFunction<Integer>(){
        public void call(Integer i){
            System.out.println(i);
        }
    });

    int count = dataSet.map(new Function<Integer, Integer>() {
        @Override
        public Integer call(Integer integer) throws Exception {
            double x = Math.random() * 2 - 1;
            double y = Math.random() * 2 - 1;
            return (x * x + y * y < 1) ? 1 : 0;
        }
    }).reduce(new Function2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer integer, Integer integer2) throws Exception {
            return integer + integer2;
        }
    });

    System.out.println("Pi is roughly " + 4.0 * count / n);
}

public static void main(String[] args) throws Exception {

    JavaSparkPi myClass = new JavaSparkPi();
    myClass.cal();
}
}

alguém tem idéia disso? obrigado!

questionAnswers(2)

yourAnswerToTheQuestion