public class XLazy<T,X extends Exception> extends Object
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.
Lazy| Modifier and Type | Method and Description |
|---|---|
T |
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.
|
static <T,X extends Exception> |
init(XSupplier<? extends T,? extends X> initial)
|
public static <T,X extends Exception> XLazy<T,X> init(XSupplier<? extends T,? extends X> initial)
XLazy instance giving a Supplier that defines the intended initialization of the
represented value.T - The result type of the initialisation code.X - The exception type that may occur within initialisation.Copyright © 2023 Andreas Kluge-Kaindl, Bremen (de). All rights reserved.