AbstractQueuedSynchronizer.ConditionObject  |  API reference  |  Android Developers (original) (raw)

open class ConditionObject : Condition, Serializable

Condition implementation for a [AbstractQueuedSynchronizer](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer) serving as the basis of a [Lock](/reference/kotlin/java/util/concurrent/locks/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 associated AbstractQueuedSynchronizer.

This class is Serializable, but all fields are transient, so deserialized conditions have no waiters.

Summary

Public constructors
ConditionObject() Creates a new ConditionObject instance.
Public methods
Unit await() Implements interruptible condition wait.
Boolean await(time: Long, unit: TimeUnit!) Implements timed condition wait.
Long awaitNanos(nanosTimeout: Long) Implements timed condition wait.
Unit awaitUninterruptibly() Implements uninterruptible condition wait.
Boolean awaitUntil(deadline: Date!) Implements absolute timed condition wait.
Unit signal() Moves the longest-waiting thread, if one exists, from the wait queue for this condition to the wait queue for the owning lock.
Unit signalAll() Moves all threads from the wait queue for this condition to the wait queue for the owning lock.
Protected methods
Int getWaitQueueLength() Returns an estimate of the number of threads waiting on this condition.
MutableCollection<Thread!>! getWaitingThreads() Returns a collection containing those threads that may be waiting on this Condition.
Boolean hasWaiters() Queries whether any threads are waiting on this condition.

Public constructors

ConditionObject

ConditionObject()

Creates a new ConditionObject instance.

Public methods

await

fun await(): Unit

Implements interruptible condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by [getState](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#getState%28%29).
  3. Invoke [release](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#release%28kotlin.Int%29) with saved state as argument, throwing IllegalMonitorStateException if it fails.
  4. Block until signalled or interrupted.
  5. Reacquire by invoking specialized version of [acquire](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#acquire%28kotlin.Int%29) with saved state as argument.
  6. If interrupted while blocked in step 4, throw InterruptedException.
Exceptions
java.lang.InterruptedException if the current thread is interrupted (and interruption of thread suspension is supported)

await

fun await(
    time: Long,
    unit: TimeUnit!
): Boolean

Implements timed condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by [getState](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#getState%28%29).
  3. Invoke [release](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#release%28kotlin.Int%29) 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 [acquire](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#acquire%28kotlin.Int%29) 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.
Parameters
time Long: the maximum time to wait
unit TimeUnit!: the time unit of the time argument
Return
Boolean false if the waiting time detectably elapsed before return from the method, else true
Exceptions
java.lang.InterruptedException if the current thread is interrupted (and interruption of thread suspension is supported)

awaitNanos

fun awaitNanos(nanosTimeout: Long): Long

Implements timed condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by [getState](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#getState%28%29).
  3. Invoke [release](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#release%28kotlin.Int%29) 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 [acquire](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#acquire%28kotlin.Int%29) with saved state as argument.
  6. If interrupted while blocked in step 4, throw InterruptedException.
Parameters
nanosTimeout Long: the maximum time to wait, in nanoseconds
Return
Long 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.
Exceptions
java.lang.InterruptedException if the current thread is interrupted (and interruption of thread suspension is supported)

awaitUninterruptibly

fun awaitUninterruptibly(): Unit

Implements uninterruptible condition wait.

  1. Save lock state returned by [getState](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#getState%28%29).
  2. Invoke [release](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#release%28kotlin.Int%29) with saved state as argument, throwing IllegalMonitorStateException if it fails.
  3. Block until signalled.
  4. Reacquire by invoking specialized version of [acquire](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#acquire%28kotlin.Int%29) with saved state as argument.

awaitUntil

fun awaitUntil(deadline: Date!): Boolean

Implements absolute timed condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by [getState](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#getState%28%29).
  3. Invoke [release](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#release%28kotlin.Int%29) 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 [acquire](/reference/kotlin/java/util/concurrent/locks/AbstractQueuedSynchronizer#acquire%28kotlin.Int%29) 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.
Parameters
deadline Date!: the absolute time to wait until
Return
Boolean false if the deadline has elapsed upon return, else true
Exceptions
java.lang.InterruptedException if the current thread is interrupted (and interruption of thread suspension is supported)

signal

fun signal(): Unit

Moves the longest-waiting thread, if one exists, from the wait queue for this condition to the wait queue for the owning lock.

Exceptions
java.lang.IllegalMonitorStateException if isHeldExclusively returns false

signalAll

fun signalAll(): Unit

Moves all threads from the wait queue for this condition to the wait queue for the owning lock.

Exceptions
java.lang.IllegalMonitorStateException if isHeldExclusively returns false

Protected methods