Class ConcurrentValue<T>


  • public final class ConcurrentValue<T>
    extends java.lang.Object
    Allow synchronization between many threads for a specific value.
     MainThread cv.set(1);
     Thread1 cv.acquire(3);
     Thread2 cv.acquire(4);
     Thread3 cv.acquire(100);
     Thread4 cv.acquire(new Object()
       {
         public boolean equals(Object other)
         {
           return other.equals(2) || other.equals(3);
         }
       });
     Thread5 cv.acquire(1);
     ...
     // Thread 1,2,3 and 4 are blocked
     // Thread 5 isn't blocked.
    
     MainThread cv.set(3);
    
     // Thread 1 and 4 are unblocked.
     // Thread 2 and 3 are still blocked.
     
    Since:
    2.0
    Author:
    Simon McDuff
    • Constructor Summary

      Constructors 
      Constructor Description
      ConcurrentValue​(T value)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void acquire​(java.lang.Object accept)
      Blocking call.
      T get()  
      void reevaluate()
      Reevaluate the condition.
      void set​(T newValue)
      Specify the new value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ConcurrentValue

        public ConcurrentValue​(T value)
    • Method Detail

      • get

        public T get()
      • set

        public void set​(T newValue)
        Specify the new value.
      • reevaluate

        public void reevaluate()
        Reevaluate the condition. It is only useful if a thread is blocked at acquire(Object) and the parameter passed changed. acquire(Object) generates a reevaluation automatically.
      • acquire

        public void acquire​(java.lang.Object accept)
                     throws java.lang.InterruptedException
        Blocking call.

        Return when value accept is equal to get().

        Throws:
        java.lang.InterruptedException