Most visited

Recently visited

Added in API level 9

AbstractQueuedLongSynchronizer.ConditionObject

public class AbstractQueuedLongSynchronizer.ConditionObject
extends Object implements Condition, Serializable

java.lang.Object
   ↳ java.util.concurrent.locks.AbstractQueuedLongSynchronizer.ConditionObject


AbstractQueuedLongSynchronizer条件实现作为 Lock实现的基础。

此类的方法文档描述了机制,而不是从锁定和条件用户的角度来看行为规范。 该类的导出版本通常需要伴随着描述依赖关联的AbstractQueuedLongSynchronizer条件语义的文档。

这个类是可序列化的,但所有字段都是暂时的,所以反序列化的条件没有服务员。

Summary

Public constructors

AbstractQueuedLongSynchronizer.ConditionObject()

创建一个新的 ConditionObject实例。

Public methods

final void await()

实施中断条件等。

final boolean await(long time, TimeUnit unit)

实现定时条件等待。

final long awaitNanos(long nanosTimeout)

实现定时条件等待。

final void awaitUninterruptibly()

实现不间断条件等待。

final boolean awaitUntil(Date deadline)

实现绝对定时条件等待。

final void signal()

将等候时间最长的线程(如果存在)从此状态的等待队列移至拥有锁的等待队列。

final void signalAll()

将此条件的等待队列中的所有线程移至拥有锁的等待队列。

Protected methods

final int getWaitQueueLength()

返回等待此条件的线程数的估计值。

final Collection<Thread> getWaitingThreads()

返回包含可能在此Condition上等待的线程的集合。

final boolean hasWaiters()

查询是否有线程正在等待这种情况。

Inherited methods

From class java.lang.Object
From interface java.util.concurrent.locks.Condition

Public constructors

AbstractQueuedLongSynchronizer.ConditionObject

Added in API level 9
AbstractQueuedLongSynchronizer.ConditionObject ()

创建一个新的 ConditionObject实例。

Public methods

await

Added in API level 9
void await ()

实施中断条件等。

  1. If current thread is interrupted, throw InterruptedException.
  2. Save lock state returned by getState().
  3. Invoke release(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(long) with saved state as argument.
  6. If interrupted while blocked in step 4, throw InterruptedException.

Throws
InterruptedException

await

Added in API level 9
boolean await (long time, 
                TimeUnit unit)

实现定时条件等待。

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

Parameters
time long: the maximum time to wait
unit TimeUnit: the time unit of the time argument
Returns
boolean false if the waiting time detectably elapsed before return from the method, else true
Throws
InterruptedException

awaitNanos

Added in API level 9
long awaitNanos (long nanosTimeout)

实现定时条件等待。

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

awaitUninterruptibly

Added in API level 9
void awaitUninterruptibly ()

Implements uninterruptible condition wait.

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

awaitUntil

Added in API level 9
boolean awaitUntil (Date deadline)

实现绝对定时条件等待。

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

Parameters
deadline Date: the absolute time to wait until
Returns
boolean false if the deadline has elapsed upon return, else true
Throws
InterruptedException

signal

Added in API level 9
void signal ()

将等候时间最长的线程(如果存在)从此状态的等待队列移至拥有锁的等待队列。

Throws
IllegalMonitorStateException if isHeldExclusively() returns false

signalAll

Added in API level 9
void signalAll ()

将此条件的等待队列中的所有线程移至拥有锁的等待队列。

Throws
IllegalMonitorStateException if isHeldExclusively() returns false

Protected methods

getWaitQueueLength

Added in API level 9
int getWaitQueueLength ()

返回等待此条件的线程数的估计值。 实现getWaitQueueLength(ConditionObject)

Returns
int the estimated number of waiting threads
Throws
IllegalMonitorStateException if isHeldExclusively() returns false

getWaitingThreads

Added in API level 9
Collection<Thread> getWaitingThreads ()

返回包含可能在此Condition上等待的线程的集合。 实现getWaitingThreads(ConditionObject)

Returns
Collection<Thread> the collection of threads
Throws
IllegalMonitorStateException if isHeldExclusively() returns false

hasWaiters

Added in API level 9
boolean hasWaiters ()

查询是否有线程正在等待这种情况。 实现hasWaiters(ConditionObject)

Returns
boolean true if there are any waiting threads
Throws
IllegalMonitorStateException if isHeldExclusively() returns false

Hooray!