File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
core/src/main/scala/org/apache/spark Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,9 @@ class SparkEnv (
9191 // actorSystem.awaitTermination()
9292
9393 // Note that blockTransferService is stopped by BlockManager since it is started by it.
94+
95+ // clear all the references in ThreadLocal object
96+ SparkEnv .reset()
9497 }
9598
9699 private [spark]
@@ -119,7 +122,7 @@ class SparkEnv (
119122}
120123
121124object SparkEnv extends Logging {
122- private val env = new ThreadLocal [SparkEnv ]
125+ @ volatile private var env = new ThreadLocal [SparkEnv ]
123126 @ volatile private var lastSetSparkEnv : SparkEnv = _
124127
125128 private [spark] val driverActorSystemName = " sparkDriver"
@@ -130,6 +133,12 @@ object SparkEnv extends Logging {
130133 env.set(e)
131134 }
132135
136+ // clear all the threadlocal references
137+ private [spark] def reset (): Unit = {
138+ env = new ThreadLocal [SparkEnv ]
139+ lastSetSparkEnv = null
140+ }
141+
133142 /**
134143 * Returns the ThreadLocal SparkEnv, if non-null. Else returns the SparkEnv
135144 * previously set in any thread.
You can’t perform that action at this time.
0 commit comments