com.holub.asynch
Class ConditionVariable
java.lang.Object
com.holub.asynch.ConditionVariable
public class ConditionVariable
- extends Object
This class is a simplified version of the com.asynch.Condition
class described in Taming Java Threads. It's really supplanted
by classes in the Java 1.5 java.util.concurrent package.
Use it to wait for some condition to become true. For example:
ConditionVariable hellFreezesOver = new ConditionVariable(false);
Thread 1:
hellFreezesOver.waitForTrue();
Thread 2:
hellFrezesOver.set(true);
Unlike wait()
you will not be suspened at all if you
wait on a true condition variable. Call set(false)
,
to put the variable back into a false condition (thereby forcing
threads to wait for the condition to become true, again).
ConditionVariable
public ConditionVariable(boolean isTrue)
isTrue
public boolean isTrue()
set
public void set(boolean how)
waitForTrue
public final void waitForTrue()
throws InterruptedException
- Throws:
InterruptedException