# AbstractQueuedLongSynchronizer.ConditionObject

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# ConditionObject

```
open class ConditionObject : Condition, Serializable
```

|---|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                                                         ||
| ↳ | [java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#) |

Condition implementation for a[AbstractQueuedLongSynchronizer](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer)serving as the basis of a[Lock](https://developer.android.com/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`AbstractQueuedLongSynchronizer`.

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

## Summary

|                                                                                             Public constructors                                                                                              ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [ConditionObject](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#ConditionObject())`()` Creates a new`ConditionObject`instance. |

|                                                                                                                                                                                                                                                 Public methods                                                                                                                                                                                                                                                  ||
|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [await](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#await())`()` Implements interruptible condition wait.                                                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [await](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#await(kotlin.Long,%20java.util.concurrent.TimeUnit))`(`time:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`, `unit:` `[TimeUnit](https://developer.android.com/reference/kotlin/java/util/concurrent/TimeUnit.html#)!`)` Implements timed condition wait. |
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)       | [awaitNanos](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#awaitNanos(kotlin.Long))`(`nanosTimeout:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Implements timed condition wait.                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [awaitUninterruptibly](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#awaitUninterruptibly())`()` Implements uninterruptible condition wait.                                                                                                                                                                                                      |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [awaitUntil](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#awaitUntil(java.util.Date))`(`deadline:` `[Date](https://developer.android.com/reference/kotlin/java/util/Date.html#)!`)` Implements absolute timed condition wait.                                                                                                                   |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [signal](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#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](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [signalAll](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#signalAll())`()` Moves all threads from the wait queue for this condition to the wait queue for the owning lock.                                                                                                                                                                       |

|                                                                                                                                                                                                                          Protected methods                                                                                                                                                                                                                           ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)                                                                                                                               | [getWaitQueueLength](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#getWaitQueueLength())`()` Returns an estimate of the number of threads waiting on this condition.            |
| [MutableCollection](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-collection/index.html)\<[Thread](https://developer.android.com/reference/kotlin/java/lang/Thread.html#)!\>! | [getWaitingThreads](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#getWaitingThreads())`()` Returns a collection containing those threads that may be waiting on this Condition. |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html)                                                                                                                       | [hasWaiters](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer.ConditionObject#hasWaiters())`()` Queries whether any threads are waiting on this condition.                                         |

## Public constructors

### ConditionObject

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
ConditionObject()
```

Creates a new`ConditionObject`instance.

## Public methods

### await

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun await(): Unit
```

Implements interruptible condition wait.

1. If current thread is interrupted, throw InterruptedException.
2. Save lock state returned by[getState](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getState()).
3. Invoke[release](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#release(kotlin.Long))with saved state as argument, throwing IllegalMonitorStateException if it fails.
4. Block until signalled or interrupted.
5. Reacquire by invoking specialized version of[acquire](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#acquire(kotlin.Long))with saved state as argument.
6. If interrupted while blocked in step 4, throw InterruptedException.

<br />

|                                                         Exceptions                                                          ||
|----------------------------------|-------------------------------------------------------------------------------------------|
| `java.lang.InterruptedException` | if the current thread is interrupted (and interruption of thread suspension is supported) |

### await

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getState()).
3. Invoke[release](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#release(kotlin.Long))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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#acquire(kotlin.Long))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.

<br />

|                                                                 Parameters                                                                 ||
|--------|------------------------------------------------------------------------------------------------------------------------------------|
| `time` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the maximum time to wait                              |
| `unit` | [TimeUnit](https://developer.android.com/reference/kotlin/java/util/concurrent/TimeUnit.html#)!:the time unit of the`time`argument |

|                                                                                   Return                                                                                    ||
|------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun awaitNanos(nanosTimeout: Long): Long
```

Implements timed condition wait.

1. If current thread is interrupted, throw InterruptedException.
2. Save lock state returned by[getState](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getState()).
3. Invoke[release](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#release(kotlin.Long))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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#acquire(kotlin.Long))with saved state as argument.
6. If interrupted while blocked in step 4, throw InterruptedException.

<br />

|                                                              Parameters                                                               ||
|----------------|-----------------------------------------------------------------------------------------------------------------------|
| `nanosTimeout` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html):the maximum time to wait, in nanoseconds |

|                                                                                                                                                                                   Return                                                                                                                                                                                   ||
|------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html) | 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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun awaitUninterruptibly(): Unit
```

Implements uninterruptible condition wait.

1. Save lock state returned by[getState](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getState()).
2. Invoke[release](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#release(kotlin.Long))with saved state as argument, throwing IllegalMonitorStateException if it fails.
3. Block until signalled.
4. Reacquire by invoking specialized version of[acquire](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#acquire(kotlin.Long))with saved state as argument.

<br />

### awaitUntil

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getState()).
3. Invoke[release](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#release(kotlin.Long))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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#acquire(kotlin.Long))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.

<br />

|                                                        Parameters                                                        ||
|------------|--------------------------------------------------------------------------------------------------------------|
| `deadline` | [Date](https://developer.android.com/reference/kotlin/java/util/Date.html#)!:the absolute time to wait until |

|                                                                     Return                                                                     ||
|------------------------------------------------------------------------------------|------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `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](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#isHeldExclusively())returns`false` |

### signalAll

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
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](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#isHeldExclusively())returns`false` |

## Protected methods

### getWaitQueueLength

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
protected fun getWaitQueueLength(): Int
```

Returns an estimate of the number of threads waiting on this condition. Implements[AbstractQueuedLongSynchronizer.getWaitQueueLength(ConditionObject)](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getWaitQueueLength(java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject)).

|                                                       Return                                                        ||
|----------------------------------------------------------------------------|-----------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the estimated number of waiting threads |

|                                                                                                 Exceptions                                                                                                  ||
|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalMonitorStateException` | if[isHeldExclusively](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#isHeldExclusively())returns`false` |

### getWaitingThreads

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
protected fun getWaitingThreads(): MutableCollection<Thread!>!
```

Returns a collection containing those threads that may be waiting on this Condition. Implements[AbstractQueuedLongSynchronizer.getWaitingThreads(ConditionObject)](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#getWaitingThreads(java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject)).

|                                                                                                              Return                                                                                                               ||
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------|
| [MutableCollection](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-collection/index.html)<[Thread](https://developer.android.com/reference/kotlin/java/lang/Thread.html#)!>! | the collection of threads |

|                                                                                                 Exceptions                                                                                                  ||
|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalMonitorStateException` | if[isHeldExclusively](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#isHeldExclusively())returns`false` |

### hasWaiters

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
protected fun hasWaiters(): Boolean
```

Queries whether any threads are waiting on this condition. Implements[AbstractQueuedLongSynchronizer.hasWaiters(ConditionObject)](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#hasWaiters(java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject)).

|                                                           Return                                                           ||
|------------------------------------------------------------------------------------|----------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if there are any waiting threads |

|                                                                                                 Exceptions                                                                                                  ||
|------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `java.lang.IllegalMonitorStateException` | if[isHeldExclusively](https://developer.android.com/reference/kotlin/java/util/concurrent/locks/AbstractQueuedLongSynchronizer#isHeldExclusively())returns`false` |