- import com.esotericsoftware.kryo.Kryo
-
- class MyRegistrator extends spark.KryoRegistrator {
-
- override def registerClasses(kryo: Kryo) {
-
- kryo.register(classOf[MyClass1])
-
- kryo.register(classOf[MyClass2])
-
- }
-
- }
-
-
- // Make sure to set these properties *before* creating a SparkContext!
-
- System.setProperty("spark.serializer", "spark.KryoSerializer")
-
- System.setProperty("spark.kryo.registrator", "mypackage.MyRegistrator")
-
- val sc = new SparkContext(...)
复制代码