Github user zsxwing commented on the pull request:

    https://github.com/apache/spark/pull/5277#issuecomment-87897974
  
    From the comments, only  `activeContext`, `contextBeingConstructed` are 
protected by `SPARK_CONTEXT_CONSTRUCTOR_LOCK`. So we can move most of codes out 
of the lock. E.g.,
    
    ```Scala
      def stop() {
        SparkContext.SPARK_CONTEXT_CONSTRUCTOR_LOCK.synchronized {
          if (!stopped) {
            stopped = true
          } else {
            logInfo("SparkContext already stopped")
            return
          }
        }
        postApplicationEnd()
        ui.foreach(_.stop())
        env.metricsSystem.report()
        metadataCleaner.cancel()
        cleaner.foreach(_.stop())
        dagScheduler.stop()
        dagScheduler = null
        listenerBus.stop()
        eventLogger.foreach(_.stop())
        env.rpcEnv.stop(heartbeatReceiver)
        progressBar.foreach(_.stop())
        taskScheduler = null
        // TODO: Cache.stop()?
        env.stop()
        SparkEnv.set(null)
        logInfo("Successfully stopped SparkContext")
        SparkContext.clearActiveContext()
      }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to