Class CountingLatch


  • public class CountingLatch
    extends java.lang.Object
    Similar to CountDownLatch except that the count can either be increased or decreased. A thread can wait until the count reaches 0. Other threads can increase or decrease the count concurrently. When count reaches 0, if there is a thread waiting for state 0, the thread will be waken up, and other threads trying to increase the count are blocked. If there is no thread waiting for state 0, then other threads can keep increasing the count. Methods can be run concurrently from different threads, the paired methods(inc() and dec(), await() and release()) do not need to be called in the same thread. An example usage is to synchronize FileSystemContext reinitialization with the ongoing RPCs. See alluxio.client.fs.FileSystemContextReinitializer for more details.
    • Constructor Summary

      Constructors 
      Constructor Description
      CountingLatch()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void await()
      Blocked during awaiting the counter to become zero.
      void dec()
      Decreases the counter.
      void inc()
      Increases the counter.
      void release()
      Unblocks threads blocked on calling inc().
      • Methods inherited from class java.lang.Object

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

      • CountingLatch

        public CountingLatch()
    • Method Detail

      • inc

        public void inc()
                 throws java.lang.InterruptedException
        Increases the counter. If await() returns, this call is blocked until release() is called.
        Throws:
        java.lang.InterruptedException - when interrupted during being blocked
      • dec

        public void dec()
        Decreases the counter. Should only be called in pair with inc(). If counter will go below zero after this call, throws Error. This method is never blocked.
      • await

        public void await()
        Blocked during awaiting the counter to become zero. When it returns, all further calls to inc() are blocked.
      • release

        public void release()
        Unblocks threads blocked on calling inc(). Should only be called in pair with await(). If not paired, throws Error. This method is never blocked.