Package de.team33.patterns.lazy.narvi
Class XLazy<T,X extends Exception>
java.lang.Object
de.team33.patterns.lazy.narvi.XLazy<T,X>
- All Implemented Interfaces:
XSupplier<T,X>
Implements a kind of supplier that provides a virtually fixed value.
That value is only actually determined when it is accessed for the first time.
This implementation ensures that the originally defined initialization code is called at most once, even if there is concurrent access from multiple threads, unless the initialization attempt causes an exception.
Once the value is established, unnecessary effort to synchronize competing* read accesses is avoided.
*Pure read accesses are of course not really competing.
-
Method Summary
-
Method Details
-
init
Returns a new instance giving aSupplierthat defines the intended initialization of the represented value.- Type Parameters:
T- The result type of the initialisation code.X- The exception type that may occur within initialisation.
-
get
Executes the originally defined initialization code once on the first call and returns its result on that and every subsequent call without executing the initialization code again.
This implementation is thread safe.
-