How to create a Singleton SparkSession in Scala Application ?
Hi Friends, Today I am going to explain how to create Singleton SparkSession in Scala Application. We can create SparkSession method in a class which returns SparkSession and call that in main class. Below is the code for the same, in which I've used Logger also to log the info. import java.util.Properties import org.apache.log4j.PropertyConfigurator import org.apache.spark.SparkConf import org.apache.spark.sql.SparkSession import org.slf4j.LoggerFactory /** * Created by anamika_singh on 2/13/2020. */ class SingletonSparkSession { val logger = LoggerFactory. getLogger ( classOf [SingletonSparkSession]) //Read the properties file and store the properties to use during processing //Creating connection to read provided variable's value in properties file. val connectionParam = new Properties connectionParam .load(getClass().getResourceAsStream( "/generic.properties" )) PropertyConfigurator. configure ( connectionParam ) //Get the require