Class SingletonMap.SingletonHolder<V>
- java.lang.Object
-
- nonapi.io.github.classgraph.concurrency.SingletonMap.SingletonHolder<V>
-
- Type Parameters:
V- the singleton type
- Enclosing class:
- SingletonMap<K,V,E extends java.lang.Exception>
private static class SingletonMap.SingletonHolder<V> extends java.lang.ObjectWrapper to allow an object instance to be put into a ConcurrentHashMap using putIfAbsent() without requiring the instance to be initialized first, so that putIfAbsent can be performed without wrapping it with a synchronized lock, and so that initialization work is not wasted if an object is already in the map for the key.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.CountDownLatchinitializedWhether or not the singleton has been initialized (the count will have reached 0 if so).private VsingletonThe singleton.
-
Constructor Summary
Constructors Modifier Constructor Description privateSingletonHolder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) Vget()Get the singleton value.(package private) voidset(V singleton)Set the singleton value, and decreases the countdown latch to 0.
-
-
-
Field Detail
-
singleton
private volatile V singleton
The singleton.
-
initialized
private final java.util.concurrent.CountDownLatch initialized
Whether or not the singleton has been initialized (the count will have reached 0 if so).
-
-
Method Detail
-
set
void set(V singleton) throws java.lang.IllegalArgumentException
Set the singleton value, and decreases the countdown latch to 0.- Parameters:
singleton- the singleton- Throws:
java.lang.IllegalArgumentException- if this method is called more than once (indicating an internal inconsistency).
-
get
V get() throws java.lang.InterruptedException
Get the singleton value.- Returns:
- the singleton value.
- Throws:
java.lang.InterruptedException- if the thread was interrupted while waiting for the value to be set.
-
-