Class SingletonMap.SingletonHolder<V>

java.lang.Object
nonapi.io.github.classgraph.concurrency.SingletonMap.SingletonHolder<V>
Type Parameters:
V - the singleton type
Enclosing class:
SingletonMap<K,V,E extends Exception>

private static class SingletonMap.SingletonHolder<V> extends Object
Wrapper to allow an object instance to be put into a ConcurrentHashMap using putIfAbsent() without requiring the instance to be initialized first, so that putIfAbsent can be performed without wrapping it with a synchronized lock, and so that initialization work is not wasted if an object is already in the map for the key.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final CountDownLatch
    Whether or not the singleton has been initialized (the count will have reached 0 if so).
    private V
    The singleton.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) V
    get()
    Get the singleton value.
    (package private) void
    set(V singleton)
    Set the singleton value, and decreases the countdown latch to 0.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • singleton

      private volatile V singleton
      The singleton.
    • initialized

      private final CountDownLatch initialized
      Whether or not the singleton has been initialized (the count will have reached 0 if so).
  • Constructor Details

    • SingletonHolder

      private SingletonHolder()
  • Method Details

    • set

      void set(V singleton) throws IllegalArgumentException
      Set the singleton value, and decreases the countdown latch to 0.
      Parameters:
      singleton - the singleton
      Throws:
      IllegalArgumentException - if this method is called more than once (indicating an internal inconsistency).
    • get

      V get() throws InterruptedException
      Get the singleton value.
      Returns:
      the singleton value.
      Throws:
      InterruptedException - if the thread was interrupted while waiting for the value to be set.