com.atlassian.jira.util.concurrent
Class BlockingCounter

java.lang.Object
  extended by com.atlassian.jira.util.concurrent.BlockingCounter

public final class BlockingCounter
extends Object

A simple counter that can will cause threads calling the await() method to block while its value is > 0. The counter may only be incremented and decremented and must have a value >= 0.

Since:
v4.1

Constructor Summary
BlockingCounter()
           
BlockingCounter(int count)
           
 
Method Summary
 void await()
          Block while counter is > 0, throwing InterruptedException if interrupted.
 boolean await(long timeout, TimeUnit unit)
           
 void awaitUninterruptibly()
          Block while counter is > 0, ignoring interrupts.
 void down()
           
 int getCount()
           
 String toString()
           
 void up()
           
 boolean wouldBlock()
          Returns true if calling await() at the same very moment would block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BlockingCounter

public BlockingCounter()

BlockingCounter

public BlockingCounter(int count)
Method Detail

up

public void up()

down

public void down()

await

public boolean await(long timeout,
                     TimeUnit unit)
              throws InterruptedException
Throws:
InterruptedException

await

public void await()
           throws InterruptedException
Block while counter is > 0, throwing InterruptedException if interrupted.

Note the behaviour has changed since v6.1 - before that InterruptedException was never thrown due to a bug.

Throws:
InterruptedException
See Also:
AbstractQueuedSynchronizer.acquireSharedInterruptibly(int)

awaitUninterruptibly

public void awaitUninterruptibly()
Block while counter is > 0, ignoring interrupts.

Since:
v6.1
See Also:
AbstractQueuedSynchronizer.doAcquireShared(int)

wouldBlock

public boolean wouldBlock()
Returns true if calling await() at the same very moment would block.

Returns:
true when count is > 0 so await() would block
Since:
v6.1

getCount

public int getCount()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2002-2014 Atlassian. All Rights Reserved.