Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-17552

Doubt about the double Synchronized in Object SparkSession.getOrCreate()

    XMLWordPrintableJSON

Details

    • Question
    • Status: Resolved
    • Trivial
    • Resolution: Invalid
    • 2.0.0
    • None
    • Spark Core, SQL
    • Important

    Description

      Because the getOrCreate() is a method of object SparkSession, only one thread can get into the first synchronized block at the same time, so I think the second synchronzied is unnecessary, of course maybe there are some other reasons, please discuss here,thank you!

       def getOrCreate(): SparkSession = synchronized {
            // Get the session from current thread's active session.
            var session = activeThreadSession.get()
            if ((session ne null) && !session.sparkContext.isStopped) {
              options.foreach { case (k, v) => session.conf.set(k, v) }
              if (options.nonEmpty) {
                logWarning("Use an existing SparkSession, some configuration may not take effect.")
              }
              return session
            }
      
            // Global synchronization so we will only set the default session once.
            SparkSession.synchronized {
             // some code here
           }
            
      
            return session
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            codlife Jianfei Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: