![JAR search and dependency download from the Maven repository](/logo.png)
sbt.internal.ClassLoadingLock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of main_2.12 Show documentation
Show all versions of main_2.12 Show documentation
sbt is an interactive build tool
/*
* sbt
* Copyright 2023, Scala center
* Copyright 2011 - 2022, Lightbend, Inc.
* Copyright 2008 - 2010, Mark Harrah
* Licensed under Apache License 2.0 (see LICENSE)
*/
package sbt.internal;
import java.util.concurrent.ConcurrentHashMap;
final class ClassLoadingLock {
interface ThrowsClassNotFound {
R get() throws ClassNotFoundException;
}
private final ConcurrentHashMap locks = new ConcurrentHashMap<>();
R withLock(final String name, final ThrowsClassNotFound supplier)
throws ClassNotFoundException {
final Object newLock = new Object();
Object prevLock;
synchronized (locks) {
prevLock = locks.putIfAbsent(name, newLock);
}
final Object lock = prevLock == null ? newLock : prevLock;
try {
synchronized (lock) {
return supplier.get();
}
} finally {
synchronized (locks) {
locks.remove(name);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy