diff options
author | Matei Zaharia <matei.zaharia@gmail.com> | 2013-08-06 15:44:05 -0700 |
---|---|---|
committer | Matei Zaharia <matei.zaharia@gmail.com> | 2013-08-06 15:44:05 -0700 |
commit | df4d10d630df7b9c67cb04ad47ec0a3e88bde9ec (patch) | |
tree | 443d7ef2b3e5c526626d12abb722afc6ffe166c2 /core | |
parent | d2b0f0c23d9ccd5e8a23450e421503d3201f3450 (diff) | |
parent | b1bbbe699cd23b937e6fa5c90d5ea0fcc9801681 (diff) | |
download | spark-df4d10d630df7b9c67cb04ad47ec0a3e88bde9ec.tar.gz spark-df4d10d630df7b9c67cb04ad47ec0a3e88bde9ec.tar.bz2 spark-df4d10d630df7b9c67cb04ad47ec0a3e88bde9ec.zip |
Merge pull request #779 from adatao/adatao-global-SparkEnv
[HOTFIX] Extend thread safety for SparkEnv.get()
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/spark/SparkEnv.scala | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/core/src/main/scala/spark/SparkEnv.scala b/core/src/main/scala/spark/SparkEnv.scala index 4a1d341f5d..0adbf1d96e 100644 --- a/core/src/main/scala/spark/SparkEnv.scala +++ b/core/src/main/scala/spark/SparkEnv.scala @@ -97,13 +97,26 @@ class SparkEnv ( object SparkEnv extends Logging { private val env = new ThreadLocal[SparkEnv] + @volatile private var lastSetSparkEnv : SparkEnv = _ def set(e: SparkEnv) { + lastSetSparkEnv = e env.set(e) } + /** + * Returns the ThreadLocal SparkEnv, if non-null. Else returns the SparkEnv + * previously set in any thread. + */ def get: SparkEnv = { - env.get() + Option(env.get()).getOrElse(lastSetSparkEnv) + } + + /** + * Returns the ThreadLocal SparkEnv. + */ + def getThreadLocal : SparkEnv = { + env.get() } def createFromSystemProperties( |