org.codehaus.gpars

groovyx.gpars.dataflow.impl
[Java] Class ResizeableCountDownLatch

java.lang.Object
  groovyx.gpars.dataflow.impl.ResizeableCountDownLatch

public final class ResizeableCountDownLatch

CountDownLatch with the ability to change the number of waiting parties

Authors:
Vaclav Pech
Doug Lea


Nested Class Summary
private static class ResizeableCountDownLatch.Sync

Synchronization control For CountDownLatch.

 
Field Summary
private ResizeableCountDownLatch.Sync sync

 
Constructor Summary
ResizeableCountDownLatch()

 
Method Summary
java.lang.Object ResizeableCountDownLatch(int count)

Constructs a CountDownLatch initialized with the given count.

boolean attemptToCountDownAndAwait(long timeout)

Attempts to atomically count down the latch and await release with a timeout.

void await()

Causes the current thread to wait until the latch has counted down to zero, unless the thread is {

linkplain:
Thread#interrupt interrupted}.

boolean await(long timeout, java.util.concurrent.TimeUnit unit)

Causes the current thread to wait until the latch has counted down to zero, unless the thread is {

linkplain:
Thread#interrupt interrupted}, or the specified waiting time elapses.

void countDown()

Decrements the count of the latch, releasing all waiting threads if the count reaches zero.

void decreaseCount()

long getCount()

Returns the current count.

void increaseCount()

boolean isReleasedFlag()

java.lang.String toString()

Returns a string identifying this latch, as well as its state.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Field Detail

sync

private final ResizeableCountDownLatch.Sync sync


 
Constructor Detail

ResizeableCountDownLatch

ResizeableCountDownLatch()


 
Method Detail

ResizeableCountDownLatch

public java.lang.Object ResizeableCountDownLatch(int count)
Constructs a CountDownLatch initialized with the given count.
throws:
IllegalArgumentException if count is negative
Parameters:
count - the number of times countDown must be invoked before threads can pass through await


attemptToCountDownAndAwait

public boolean attemptToCountDownAndAwait(long timeout)
Attempts to atomically count down the latch and await release with a timeout. If the timeout expires, the count is increased and the latch is re-tested before reporting failed timeout.
throws:
InterruptedException If the thread gets interrupted while waiting for the release
Parameters:
timeout - The time in nanoseconds to await
Returns:
True, if successful, false, is the timeout elapses without the latch being released


await

public void await()
Causes the current thread to wait until the latch has counted down to zero, unless the thread is {
linkplain:
Thread#interrupt interrupted}.

If the current count is zero then this method returns immediately.

If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of two things happen:

  • The count reaches zero due to invocations of the countDown method; or
  • Some other thread {@linkplain Thread#interrupt interrupts} the current thread.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is {@linkplain Thread#interrupt interrupted} while waiting,
then java.lang.InterruptedException is thrown and the current thread's interrupted status is cleared.
throws:
InterruptedException if the current thread is interrupted while waiting


await

public boolean await(long timeout, java.util.concurrent.TimeUnit unit)
Causes the current thread to wait until the latch has counted down to zero, unless the thread is {
linkplain:
Thread#interrupt interrupted}, or the specified waiting time elapses.

If the current count is zero then this method returns immediately with the value true.

If the current count is greater than zero then the current thread becomes disabled for thread scheduling purposes and lies dormant until one of three things happen:

  • The count reaches zero due to invocations of the countDown method; or
  • Some other thread {@linkplain Thread#interrupt interrupts} the current thread; or
  • The specified waiting time elapses.

If the count reaches zero then the method returns with the value true.

If the current thread:

  • has its interrupted status set on entry to this method; or
  • is {@linkplain Thread#interrupt interrupted} while waiting,
then java.lang.InterruptedException is thrown and the current thread's interrupted status is cleared.

If the specified waiting time elapses then the value false is returned. If the time is less than or equal to zero, the method will not wait at all.

throws:
InterruptedException if the current thread is interrupted while waiting
Parameters:
timeout - the maximum time to wait
unit - the time unit of the timeout argument
Returns:
true if the count reached zero and false if the waiting time elapsed before the count reached zero


countDown

public void countDown()
Decrements the count of the latch, releasing all waiting threads if the count reaches zero.

If the current count is greater than zero then it is decremented. If the new count is zero then all waiting threads are re-enabled for thread scheduling purposes.

If the current count equals zero then nothing happens.


decreaseCount

public void decreaseCount()


getCount

public long getCount()
Returns the current count.

This method is typically used for debugging and testing purposes.

Returns:
the current count


increaseCount

public void increaseCount()


isReleasedFlag

public boolean isReleasedFlag()


toString

public java.lang.String toString()
Returns a string identifying this latch, as well as its state. The state, in brackets, includes the String "Count =" followed by the current count.
Returns:
a string identifying this latch, as well as its state


 

Copyright © 2008–2012 Václav Pech. All Rights Reserved.