Skip to content

Commit 8071541

Browse files
committed
Merge branch 'env' into streaming
2 parents c7bbbce + 4d0ea8b commit 8071541

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/src/main/scala/org/apache/spark/SparkEnv.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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

121124
object 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.

0 commit comments

Comments
 (0)