I am looking for a good way to ensure that my application uses only one Spark Context (sc). During development, I often encounter errors and must restart my game! server to check my changes. Would a Singleton template be a solution?
object sparckContextSingleton {
@transient private var instance: SparkContext = _
private val conf : SparkConf = new SparkConf()
.setMaster("local[2]")
.setAppName("myApp")
def getInstance(): SparkContext = {
if (instance == null){
instance = new SparkContext(conf)
}
instance
}
}
It does not do a good job. Should I stop SparkContext?
source
share