不可序列化的任務(wù):java.io.NotSerializableException僅在類在調(diào)用閉包之外的函數(shù)時(shí),會(huì)產(chǎn)生奇怪的行為:當(dāng)函數(shù)在對(duì)象中時(shí),一切都在工作。當(dāng)函數(shù)在類中時(shí),獲?。翰豢尚蛄谢娜蝿?wù):java.io.NotSerializableException:測(cè)試問題是,我需要類中的代碼,而不是對(duì)象。知道為什么會(huì)這樣嗎?Scala對(duì)象是序列化的(默認(rèn)嗎?)這是一個(gè)工作代碼示例: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(_))}這是一個(gè)不起作用的例子: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}
不可序列化的任務(wù):java.io.NotSerializableException僅在類
紅糖糍粑
2019-07-01 15:30:40