-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
await()
Causes the current thread to wait until it is signalled or interrupted.long
awaitNanos
(long timeoutNS) Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses.void
clear()
Clears this waiter and release resources.getId()
Returns the identification ornull
if none defined.getValue()
Returns the value of this waiter ornull
if none available.boolean
hasId()
Returnstrue
this waiter has an identification.void
initialize
(String id) Initialize this waiter for a new wait operation.void
lock()
Acquires the lock.void
Changes the value of this waiter.void
signal()
Wakes up one waiting thread.void
Wakes up all waiting threads.void
unlock()
Attempts to release this lock.
-
Constructor Details
-
Waiter
public Waiter()Constructs a newWaiter
instance.
-
-
Method Details
-
clear
public void clear()Clears this waiter and release resources. -
initialize
Initialize this waiter for a new wait operation.- Parameters:
id
- the new identification of the waiter.- Throws:
NullPointerException
- ifid
isnull
.
-
hasId
public boolean hasId()Returnstrue
this waiter has an identification.- Returns:
true
this waiter has an identification.
-
getId
Returns the identification ornull
if none defined.- Returns:
- the identification or
null
if none defined.
-
getValue
Returns the value of this waiter ornull
if none available.- Returns:
- the value of this waiter or
null
if none available.
-
setValue
Changes the value of this waiter.- Parameters:
value
- the new value of this waiter.- Throws:
NullPointerException
- ifvalue
isnull
.
-
lock
public void lock()Acquires the lock.Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one.
If the current thread already holds the lock then the hold count is incremented by one and the method returns immediately.
If the lock is held by another thread then the current thread becomes disabled for thread scheduling purposes and lies dormant until the lock has been acquired, at which time the lock hold count is set to one.
- See Also:
-
await
Causes the current thread to wait until it is signalled or interrupted.- Throws:
InterruptedException
- if the current thread is interrupted.- See Also:
-
awaitNanos
Causes the current thread to wait until it is signalled or interrupted, or the specified waiting time elapses.- Parameters:
timeoutNS
- the maximum time to wait (nanoseconds).- Returns:
- an estimate of the
timeoutNS
value minus the time spent waiting upon return from this method. A positive value may be used as the argument to a subsequent call to this method to finish waiting out the desired time. A value less than or equal to zero indicates that no time remains. - Throws:
InterruptedException
- if the current thread is interrupted.- See Also:
-
signal
public void signal()Wakes up one waiting thread.If any threads are waiting on this condition then one is selected for waking up. That thread must then re-acquire the lock before returning from
awaitNanos
.- See Also:
-
signalAll
public void signalAll()Wakes up all waiting threads.If any threads are waiting on this condition then they are all woken up. Each thread must re-acquire the lock before it can return from
awaitNanos
.- See Also:
-
unlock
public void unlock()Attempts to release this lock.If the current thread is the holder of this lock then the hold count is decremented. If the hold count is now zero then the lock is released. If the current thread is not the holder of this lock then
IllegalMonitorStateException
is thrown.- Throws:
IllegalMonitorStateException
- if thread doesn't hold this lock.- See Also:
-