Class Overview
Class that implements the condition variable locking paradigm.
This differs from the built-in java.lang.Object wait() and notify()
in that this class contains the condition to wait on itself. That means
open(), close() and block() are sticky. If open() is called before block(),
block() will not block, and instead return immediately.
This class uses itself is at the object to wait on, so if you wait()
or notify() on a ConditionVariable, the results are undefined.
Summary
Public Constructors |
|
ConditionVariable()
Create the ConditionVariable in the default closed state.
|
|
ConditionVariable(boolean state)
Create the ConditionVariable with the given state.
|
Public Methods |
boolean
|
block(long timeout)
Block the current thread until the condition is opened or until
timeout milliseconds have passed.
|
void
|
block()
Block the current thread until the condition is opened.
|
void
|
close()
Reset the condition to the closed state.
|
void
|
open()
Open the condition, and release all threads that are blocked.
|
[Expand]
Inherited Methods |
From class java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Is called before the object's memory is being reclaimed by the VM.
|
final
Class<? extends Object>
|
getClass()
Returns the unique instance of Class which represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
|
Public Constructors
public
ConditionVariable
()
Create the ConditionVariable in the default closed state.
public
ConditionVariable
(boolean state)
Create the ConditionVariable with the given state.
Pass true for opened and false for closed.
Public Methods
public
boolean
block
(long timeout)
Block the current thread until the condition is opened or until
timeout milliseconds have passed.
If the condition is already opened, return immediately.
Parameters
timeout
| the minimum time to wait in milliseconds. |
Returns
- true if the condition was opened, false if the call returns
because of the timeout.
public
void
block
()
Block the current thread until the condition is opened.
If the condition is already opened, return immediately.
public
void
close
()
Reset the condition to the closed state.
Any threads that call block() will block until someone calls open.
public
void
open
()
Open the condition, and release all threads that are blocked.
Any threads that later approach block() will not block unless close()
is called.