Skip to content

Commit

Permalink
chore: Use ReentrantLock for loading Extension Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
He-Pin committed Apr 10, 2024
1 parent 45b5d44 commit 267322d
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -120,6 +121,7 @@ public class ExtensionLoader<T> {

private final ConcurrentMap<Class<?>, String> cachedNames = new ConcurrentHashMap<>();

private final ReentrantLock loadExtensionClassesLock = new ReentrantLock();
private final Holder<Map<String, Class<?>>> cachedClasses = new Holder<>();

private final Map<String, Object> cachedActivates = Collections.synchronizedMap(new LinkedHashMap<>());
Expand Down Expand Up @@ -951,7 +953,8 @@ private Class<?> getExtensionClass(String name) {
private Map<String, Class<?>> getExtensionClasses() {
Map<String, Class<?>> classes = cachedClasses.get();
if (classes == null) {
synchronized (cachedClasses) {
loadExtensionClassesLock.lock();
try {
classes = cachedClasses.get();
if (classes == null) {
try {
Expand All @@ -968,6 +971,8 @@ private Map<String, Class<?>> getExtensionClasses() {
}
cachedClasses.set(classes);
}
} finally {
loadExtensionClassesLock.unlock();
}
}
return classes;
Expand Down

0 comments on commit 267322d

Please sign in to comment.