spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Owen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (SPARK-17552) Doubt about the double Synchronized in Object SparkSession.getOrCreate()
Date Thu, 15 Sep 2016 07:57:21 GMT

    [ https://issues.apache.org/jira/browse/SPARK-17552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15492689#comment-15492689
] 

Sean Owen commented on SPARK-17552:
-----------------------------------

The comments explain why one lock is used over the other

> Doubt about the double Synchronized in Object SparkSession.getOrCreate()
> ------------------------------------------------------------------------
>
>                 Key: SPARK-17552
>                 URL: https://issues.apache.org/jira/browse/SPARK-17552
>             Project: Spark
>          Issue Type: Question
>          Components: Spark Core, SQL
>    Affects Versions: 2.0.0
>            Reporter: Jianfei Wang
>            Priority: Trivial
>              Labels: features
>
> 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!

> {code}
>  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
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message