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 anOptionalrepresenting 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 customLockinstance.
-
-
Method Details
-
get
Description copied from interface:LazyValueGets the value of thisSimpleLazyValue, computing it if it was not already computed. -
getOptional
Description copied from interface:LazyValueGets anOptionalrepresenting thisSimpleLazyValue. If the value was not previously loaded, then this simply returns an empty.- Specified by:
getOptionalin interfaceLazyValue<T>- Returns:
- the
Optionalrepresenting the value
-