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 Exception>
Wrapper 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
FieldsModifier and TypeFieldDescriptionprivate final CountDownLatch
Whether or not the singleton has been initialized (the count will have reached 0 if so).private V
The singleton. -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
singleton
The singleton. -
initialized
Whether or not the singleton has been initialized (the count will have reached 0 if so).
-
-
Constructor Details
-
SingletonHolder
private SingletonHolder()
-
-
Method Details
-
set
Set the singleton value, and decreases the countdown latch to 0.- Parameters:
singleton
- the singleton- Throws:
IllegalArgumentException
- if this method is called more than once (indicating an internal inconsistency).
-
get
Get the singleton value.- Returns:
- the singleton value.
- Throws:
InterruptedException
- if the thread was interrupted while waiting for the value to be set.
-