com.jpeterson.util
Class Condition

java.lang.Object
  |
  +--com.jpeterson.util.Condition

public class Condition
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Constructor Summary
Condition(boolean isTrue)
          Create a new condition variable in a known state.
 
Method Summary
 boolean isTrue()
          See if the condition variable is true (without releasing).
 void releaseAll()
          Release all waiting threads without setting the condition true.
 void releaseOne()
          Release one waiting thread without setting the condition true.
 void setFalse()
          Set the condition to false.
 void setTrue()
          Set the condition to true.
 void waitForTrue()
          Wait (potentially forever) for the condition to become true.
 void waitForTrue(long timeout)
          Wait for the condition to become true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Condition

public Condition(boolean isTrue)
Create a new condition variable in a known state.

Derived from Java World article

Parameters:
isTrue - initial state of condition variable
Method Detail

isTrue

public boolean isTrue()
See if the condition variable is true (without releasing).
Returns:
state of the condition variable

setFalse

public void setFalse()
Set the condition to false. Waiting threads are not affected.

setTrue

public void setTrue()
Set the condition to true. Waiting threads are not affected.

releaseAll

public void releaseAll()
Release all waiting threads without setting the condition true.

releaseOne

public void releaseOne()
Release one waiting thread without setting the condition true.

waitForTrue

public void waitForTrue(long timeout)
                 throws java.lang.InterruptedException
Wait for the condition to become true.
Parameters:
timeout - Timeout in milliseconds

waitForTrue

public void waitForTrue()
                 throws java.lang.InterruptedException
Wait (potentially forever) for the condition to become true.
Parameters:
timeout - Timeout in milliseconds