Class LazyLoaded<T>

java.lang.Object
net.adoptopenjdk.icedteaweb.LazyLoaded<T>
Type Parameters:
T - the type of the object to lazy load.
All Implemented Interfaces:
Supplier<T>

public class LazyLoaded<T> extends Object implements Supplier<T>
Generic wrapper for thread safe lazy loading. For details see: https://en.wikipedia.org/wiki/Double-checked_locking#Usage_in_Java
  • Field Details

    • supplier

      private Supplier<T> supplier
    • instance

      private volatile T instance
  • Constructor Details

    • LazyLoaded

      public LazyLoaded(Supplier<T> supplier)
      Parameters:
      supplier - supplier to load the value lazy upon first request. Must not be null and should not return null.
  • Method Details

    • get

      public T get()
      Specified by:
      get in interface Supplier<T>
      Returns:
      the value which is lazy loaded if necessary.
    • isLoaded

      public boolean isLoaded()
      Returns:
      true iff the data has been loaded