zoukankan      html  css  js  c++  java
  • spark Task not serializable

    Job aborted due to stage failure: Task not serializable:

    If you see this error:

    org.apache.spark.SparkException: Job aborted due to stage failure: Task not serializable: java.io.NotSerializableException: ...
    

    The above error can be triggered when you intialize a variable on the driver (master), but then try to use it on one of the workers. In that case, Spark Streaming will try to serialize the object to send it over to the worker, and fail if the object is not serializable. Consider the following code snippet:

    NotSerializable notSerializable = new NotSerializable();
    JavaRDD<String> rdd = sc.textFile("/tmp/myfile");
    
    rdd.map(s -> notSerializable.doSomething(s)).collect();
    

    This will trigger that error. Here are some ideas to fix this error:

    • Serializable the class
    • Declare the instance only within the lambda function passed in map.
    • Make the NotSerializable object as a static and create it once per machine.
    • Call rdd.forEachPartition and create the NotSerializable object in there like this:
    rdd.forEachPartition(iter -> {
      NotSerializable notSerializable = new NotSerializable();
    
      // ...Now process iter
    });

    参考:https://databricks.gitbooks.io/databricks-spark-knowledge-base/content/troubleshooting/javaionotserializableexception.html
  • 相关阅读:
    Release和Debug的区别[转]
    SVM运用到多分类[引]
    HMM
    [转] 数据挖掘 机器学习 模式识别的关系
    [转]mysql 数据导入
    java 获取当前时间戳
    二叉树遍历建树[zhuan]
    关于c指针[转]
    词法分析
    组合数据类型练习,综合练习
  • 原文地址:https://www.cnblogs.com/pingjie/p/6595169.html
Copyright © 2011-2022 走看看