Class ConcurrentInitialize<T>

  • Type Parameters:
    T -

    public abstract class ConcurrentInitialize<T>
    extends java.lang.Object
    Helper class to handle concurrent system where you need to initialize a value. The first one should create the value but the others should block until the value has been created. Since we do not want to hold a lock during the creation this is kind of tricky. This class uses a single monitor lock that oeprates a state machine.
    • Field Detail

      • value

        private T value
      • lock

        private java.lang.Object lock
      • creatingThread

        private java.lang.Thread creatingThread
      • exception

        private java.lang.Exception exception
    • Constructor Detail

      • ConcurrentInitialize

        public ConcurrentInitialize()
    • Method Detail

      • get

        public T get()
              throws java.lang.Exception
        Get the value or wait until it is created.
        Throws:
        java.lang.Exception
      • create

        public abstract T create()
                          throws java.lang.Exception
        Override to create the actual object
        Returns:
        the actual object, could be null
        Throws:
        java.lang.Exception - if the creation failed this is the exception that was thrown