不可序列化的任務:java.io.NotSerializableException僅在類在調用閉包之外的函數時,會產生奇怪的行為:當函數在對象中時,一切都在工作。當函數在類中時,獲?。翰豢尚蛄谢娜蝿眨簀ava.io.NotSerializableException:測試問題是,我需要類中的代碼,而不是對象。知道為什么會這樣嗎?Scala對象是序列化的(默認嗎?)這是一個工作代碼示例:object working extends App {
val list = List(1,2,3)
val rddList = Spark.ctx.parallelize(list)
//calling function outside closure
val after = rddList.map(someFunc(_))
def someFunc(a:Int) = a+1
after.collect().map(println(_))}這是一個不起作用的例子:object NOTworking extends App {
new testing().doIT}//adding extends Serializable wont helpclass testing {
val list = List(1,2,3)
val rddList = Spark.ctx.parallelize(list)
def doIT = {
//again calling the fucntion someFunc
val after = rddList.map(someFunc(_))
//this will crash (spark lazy)
after.collect().map(println(_))
}
def someFunc(a:Int) = a+1}
添加回答
舉報
0/150
提交
取消