Skip to content

Commit e679711

Browse files
mnazbroRobert Kruszewski
authored andcommitted
Use synchronized instead of a lock
[SPARK-25891][PYTHON] Upgrade to Py4J 0.10.8.1
1 parent a5a73e0 commit e679711

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

core/src/main/scala/org/apache/spark/api/conda/CondaEnvironmentManager.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import java.nio.file.Files
2020
import java.nio.file.Path
2121
import java.nio.file.Paths
2222
import java.nio.file.attribute.PosixFilePermission
23-
import java.util.concurrent.locks.ReentrantLock
2423
import java.util.regex.Pattern
2524

2625
import scala.collection.JavaConverters._
@@ -213,7 +212,6 @@ object CondaEnvironmentManager extends Logging {
213212
private[this] val httpUrlToken =
214213
Pattern.compile("(\\b\\w+://[^:/@]*:)([^/@]+)(?=@([\\w-.]+)(:\\d+)?\\b)")
215214

216-
private[this] val initializedEnvironmentsLock = new ReentrantLock()
217215
private[this] val initializedEnvironments =
218216
mutable.HashMap[CondaSetupInstructions, CondaEnvironment]()
219217

@@ -249,17 +247,14 @@ object CondaEnvironmentManager extends Logging {
249247
* a new one if none exists.
250248
*/
251249
def getOrCreateCondaEnvironment(instructions: CondaSetupInstructions): CondaEnvironment = {
252-
initializedEnvironmentsLock.lock()
253-
try {
250+
this.synchronized {
254251
initializedEnvironments.get(instructions) match {
255252
case Some(condaEnv) => condaEnv
256253
case None =>
257254
val condaEnv = createCondaEnvironment(instructions)
258255
initializedEnvironments.put(instructions, condaEnv)
259256
condaEnv
260257
}
261-
} finally {
262-
initializedEnvironmentsLock.unlock()
263258
}
264259
}
265260

0 commit comments

Comments
 (0)