Class ThreadSafeLazyValue<T>
java.lang.Object
dev.getelements.elements.sdk.util.ThreadSafeLazyValue<T>
- Type Parameters:
T
- the type of value to supply
A thread-safe implementation of
SimpleLazyValue
.
This uses a Lock
to perform the synchronization.-
Constructor Summary
ConstructorsConstructorDescriptionThreadSafeLazyValue
(Supplier<T> tSupplier) Creates an instance ofThreadSafeLazyValue<T>
with default lock.ThreadSafeLazyValue
(Supplier<T> tSupplier, Lock lock) Creates an instance ofThreadSafeLazyValue<T>
with default lock. -
Method Summary
Modifier and TypeMethodDescriptionget()
Gets the value of thisSimpleLazyValue
, computing it if it was not already computed.Gets anOptional
representing thisSimpleLazyValue
.
-
Constructor Details
-
ThreadSafeLazyValue
Creates an instance ofThreadSafeLazyValue<T>
with default lock. This constructor uses the constructorReentrantLock()
to construct the lock using the default fairness option. -
ThreadSafeLazyValue
Creates an instance ofThreadSafeLazyValue<T>
with default lock. This constructor allows for the specification of a customLock
instance.
-
-
Method Details
-
get
Description copied from interface:LazyValue
Gets the value of thisSimpleLazyValue
, computing it if it was not already computed. -
getOptional
Description copied from interface:LazyValue
Gets anOptional
representing thisSimpleLazyValue
. If the value was not previously loaded, then this simply returns an empty.- Specified by:
getOptional
in interfaceLazyValue<T>
- Returns:
- the
Optional
representing the value
-