AbstractQueuedSynchronizer.ConditionObject (Java SE 9 & JDK 9 ) (original) (raw)
- java.util.concurrent.locks.AbstractQueuedSynchronizer.ConditionObject
All Implemented Interfaces:
[Serializable](../../../../java/io/Serializable.html "interface in java.io")
,[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")
Enclosing class:
AbstractQueuedSynchronizer
public class AbstractQueuedSynchronizer.ConditionObject
extends Object
implements Condition, Serializable
Condition implementation for a AbstractQueuedSynchronizer serving as the basis of a Lock implementation.
Method documentation for this class describes mechanics, not behavioral specifications from the point of view of Lock and Condition users. Exported versions of this class will in general need to be accompanied by documentation describing condition semantics that rely on those of the associatedAbstractQueuedSynchronizer
.
This class is Serializable, but all fields are transient, so deserialized conditions have no waiters.
See Also:
Serialized Form
Constructor Summary
Constructors
Constructor Description ConditionObject() Creates a new ConditionObject instance. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description void await() Implements interruptible condition wait. boolean await(long time,TimeUnit unit) Implements timed condition wait. long awaitNanos(long nanosTimeout) Implements timed condition wait. void awaitUninterruptibly() Implements uninterruptible condition wait. boolean awaitUntil(Date deadline) Implements absolute timed condition wait. protected Collection<Thread> getWaitingThreads() Returns a collection containing those threads that may be waiting on this Condition. protected int getWaitQueueLength() Returns an estimate of the number of threads waiting on this condition. protected boolean hasWaiters() Queries whether any threads are waiting on this condition. void signal() Moves the longest-waiting thread, if one exists, from the wait queue for this condition to the wait queue for the owning lock. void signalAll() Moves all threads from the wait queue for this condition to the wait queue for the owning lock. * ### Methods inherited from class java.lang.[Object](../../../../java/lang/Object.html "class in java.lang") `[clone](../../../../java/lang/Object.html#clone--), [equals](../../../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../../../java/lang/Object.html#finalize--), [getClass](../../../../java/lang/Object.html#getClass--), [hashCode](../../../../java/lang/Object.html#hashCode--), [notify](../../../../java/lang/Object.html#notify--), [notifyAll](../../../../java/lang/Object.html#notifyAll--), [toString](../../../../java/lang/Object.html#toString--), [wait](../../../../java/lang/Object.html#wait--), [wait](../../../../java/lang/Object.html#wait-long-), [wait](../../../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### ConditionObject public ConditionObject() Creates a new `ConditionObject` instance.
Method Detail
* #### signal public final void signal() Moves the longest-waiting thread, if one exists, from the wait queue for this condition to the wait queue for the owning lock. Specified by: `[signal](../../../../java/util/concurrent/locks/Condition.html#signal--)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Throws: `[IllegalMonitorStateException](../../../../java/lang/IllegalMonitorStateException.html "class in java.lang")` \- if [AbstractQueuedSynchronizer.isHeldExclusively()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#isHeldExclusively--) returns `false` * #### signalAll public final void signalAll() Moves all threads from the wait queue for this condition to the wait queue for the owning lock. Specified by: `[signalAll](../../../../java/util/concurrent/locks/Condition.html#signalAll--)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Throws: `[IllegalMonitorStateException](../../../../java/lang/IllegalMonitorStateException.html "class in java.lang")` \- if [AbstractQueuedSynchronizer.isHeldExclusively()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#isHeldExclusively--) returns `false` * #### awaitUninterruptibly public final void awaitUninterruptibly() Specified by: `[awaitUninterruptibly](../../../../java/util/concurrent/locks/Condition.html#awaitUninterruptibly--)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` * #### await public final void await() throws [InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang") Implements interruptible condition wait. 1. If current thread is interrupted, throw InterruptedException. 2. Save lock state returned by [AbstractQueuedSynchronizer.getState()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#getState--). 3. Invoke [AbstractQueuedSynchronizer.release(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#release-int-) with saved state as argument, throwing IllegalMonitorStateException if it fails. 4. Block until signalled or interrupted. 5. Reacquire by invoking specialized version of[AbstractQueuedSynchronizer.acquire(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#acquire-int-) with saved state as argument. 6. If interrupted while blocked in step 4, throw InterruptedException. Specified by: `[await](../../../../java/util/concurrent/locks/Condition.html#await--)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Throws: `[InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread is interrupted (and interruption of thread suspension is supported) * #### awaitNanos public final long awaitNanos(long nanosTimeout) throws [InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang") Implements timed condition wait. 1. If current thread is interrupted, throw InterruptedException. 2. Save lock state returned by [AbstractQueuedSynchronizer.getState()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#getState--). 3. Invoke [AbstractQueuedSynchronizer.release(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#release-int-) with saved state as argument, throwing IllegalMonitorStateException if it fails. 4. Block until signalled, interrupted, or timed out. 5. Reacquire by invoking specialized version of[AbstractQueuedSynchronizer.acquire(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#acquire-int-) with saved state as argument. 6. If interrupted while blocked in step 4, throw InterruptedException. Specified by: `[awaitNanos](../../../../java/util/concurrent/locks/Condition.html#awaitNanos-long-)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Parameters: `nanosTimeout` \- the maximum time to wait, in nanoseconds Returns: an estimate of the `nanosTimeout` 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](../../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread is interrupted (and interruption of thread suspension is supported) * #### awaitUntil public final boolean awaitUntil([Date](../../../../java/util/Date.html "class in java.util") deadline) throws [InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang") Implements absolute timed condition wait. 1. If current thread is interrupted, throw InterruptedException. 2. Save lock state returned by [AbstractQueuedSynchronizer.getState()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#getState--). 3. Invoke [AbstractQueuedSynchronizer.release(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#release-int-) with saved state as argument, throwing IllegalMonitorStateException if it fails. 4. Block until signalled, interrupted, or timed out. 5. Reacquire by invoking specialized version of[AbstractQueuedSynchronizer.acquire(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#acquire-int-) with saved state as argument. 6. If interrupted while blocked in step 4, throw InterruptedException. 7. If timed out while blocked in step 4, return false, else true. Specified by: `[awaitUntil](../../../../java/util/concurrent/locks/Condition.html#awaitUntil-java.util.Date-)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Parameters: `deadline` \- the absolute time to wait until Returns: `false` if the deadline has elapsed upon return, else`true` Throws: `[InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread is interrupted (and interruption of thread suspension is supported) * #### await public final boolean await(long time, [TimeUnit](../../../../java/util/concurrent/TimeUnit.html "enum in java.util.concurrent") unit) throws [InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang") Implements timed condition wait. 1. If current thread is interrupted, throw InterruptedException. 2. Save lock state returned by [AbstractQueuedSynchronizer.getState()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#getState--). 3. Invoke [AbstractQueuedSynchronizer.release(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#release-int-) with saved state as argument, throwing IllegalMonitorStateException if it fails. 4. Block until signalled, interrupted, or timed out. 5. Reacquire by invoking specialized version of[AbstractQueuedSynchronizer.acquire(int)](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#acquire-int-) with saved state as argument. 6. If interrupted while blocked in step 4, throw InterruptedException. 7. If timed out while blocked in step 4, return false, else true. Specified by: `[await](../../../../java/util/concurrent/locks/Condition.html#await-long-java.util.concurrent.TimeUnit-)` in interface `[Condition](../../../../java/util/concurrent/locks/Condition.html "interface in java.util.concurrent.locks")` Parameters: `time` \- the maximum time to wait `unit` \- the time unit of the `time` argument Returns: `false` if the waiting time detectably elapsed before return from the method, else `true` Throws: `[InterruptedException](../../../../java/lang/InterruptedException.html "class in java.lang")` \- if the current thread is interrupted (and interruption of thread suspension is supported) * #### hasWaiters protected final boolean hasWaiters() Returns: `true` if there are any waiting threads Throws: `[IllegalMonitorStateException](../../../../java/lang/IllegalMonitorStateException.html "class in java.lang")` \- if [AbstractQueuedSynchronizer.isHeldExclusively()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#isHeldExclusively--) returns `false` * #### getWaitQueueLength protected final int getWaitQueueLength() Returns: the estimated number of waiting threads Throws: `[IllegalMonitorStateException](../../../../java/lang/IllegalMonitorStateException.html "class in java.lang")` \- if [AbstractQueuedSynchronizer.isHeldExclusively()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#isHeldExclusively--) returns `false` * #### getWaitingThreads protected final [Collection](../../../../java/util/Collection.html "interface in java.util")<[Thread](../../../../java/lang/Thread.html "class in java.lang")> getWaitingThreads() Returns: the collection of threads Throws: `[IllegalMonitorStateException](../../../../java/lang/IllegalMonitorStateException.html "class in java.lang")` \- if [AbstractQueuedSynchronizer.isHeldExclusively()](../../../../java/util/concurrent/locks/AbstractQueuedSynchronizer.html#isHeldExclusively--) returns `false`
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2017, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.