Added in API level 9

ConditionObject

open class ConditionObject : Condition, Serializable
kotlin.Any
   ↳ java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject

Condition implementation for a AbstractQueuedLongSynchronizer 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 associated AbstractQueuedLongSynchronizer.

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

Summary

Public constructors

Creates a new ConditionObject instance.

Public methods
Unit

Implements interruptible condition wait.

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

Implements timed condition wait.

Long
awaitNanos(nanosTimeout: Long)

Implements timed condition wait.

Unit

Implements uninterruptible condition wait.

Boolean
awaitUntil(deadline: Date!)

Implements absolute timed condition wait.

Unit

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

Unit

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

Protected methods
Int

Returns an estimate of the number of threads waiting on this condition.

MutableCollection<Thread!>!

Returns a collection containing those threads that may be waiting on this Condition.

Boolean

Queries whether any threads are waiting on this condition.

Public constructors

ConditionObject

Added in API level 9
ConditionObject()

Creates a new ConditionObject instance.

Public methods

await

Added in API level 9
fun await(): Unit

Implements interruptible condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by getState.
  3. Invoke release with saved state as argument, throwing IllegalMonitorStateException if it fails.
  4. Block until signalled or interrupted.
  5. Reacquire by invoking specialized version of acquire 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

Added in API level 9
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.
  3. Invoke release 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 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

Added in API level 9
fun awaitNanos(nanosTimeout: Long): Long

Implements timed condition wait.

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by getState.
  3. Invoke release 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 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

Added in API level 9
fun awaitUninterruptibly(): Unit

Implements uninterruptible condition wait.

  1. Save lock state returned by getState.
  2. Invoke release with saved state as argument, throwing IllegalMonitorStateException if it fails.
  3. Block until signalled.
  4. Reacquire by invoking specialized version of acquire with saved state as argument.

awaitUntil

Added in API level 9
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.
  3. Invoke release 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 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

Added in API level 9
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

Added in API level 9
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

getWaitQueueLength

Added in API level 9
protected fun getWaitQueueLength(): Int

Returns an estimate of the number of threads waiting on this condition. Implements AbstractQueuedLongSynchronizer#getWaitQueueLength(ConditionObject).

Return
Int the estimated number of waiting threads
Exceptions
java.lang.IllegalMonitorStateException if isHeldExclusively returns false

getWaitingThreads

Added in API level 9
protected fun getWaitingThreads(): MutableCollection<Thread!>!

Returns a collection containing those threads that may be waiting on this Condition. Implements AbstractQueuedLongSynchronizer#getWaitingThreads(ConditionObject).

Return
MutableCollection<Thread!>! the collection of threads
Exceptions
java.lang.IllegalMonitorStateException if isHeldExclusively returns false

hasWaiters

Added in API level 9
protected fun hasWaiters(): Boolean

Queries whether any threads are waiting on this condition. Implements AbstractQueuedLongSynchronizer#hasWaiters(ConditionObject).

Return
Boolean true if there are any waiting threads
Exceptions
java.lang.IllegalMonitorStateException if isHeldExclusively returns false