public abstract class AbstractQueuedLongSynchronizer extends AbstractOwnableSynchronizer implements Serializable
AbstractQueuedSynchronizer,作为
long保持同步状态。这类具有完全相同的结构,性质,方法为除所有状态有关的参数和结果定义为
long而不是
int
AbstractQueuedSynchronizer。这类可能是有用的创建同步器如多级锁和障碍,需要64位的状态时。
看使用说明和例子AbstractQueuedSynchronizer。
| Modifier and Type | Class and Description |
|---|---|
class |
AbstractQueuedLongSynchronizer.ConditionObject
一
AbstractQueuedLongSynchronizer作为一个
Lock实施的基础条件的实现。
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractQueuedLongSynchronizer()
创建一个新的具有零初始同步状态
AbstractQueuedLongSynchronizer实例。
|
| Modifier and Type | Method and Description |
|---|---|
void |
acquire(long arg)
在独占模式中获得,忽略中断。
|
void |
acquireInterruptibly(long arg)
获取独占模式,如果中断中止。
|
void |
acquireShared(long arg)
在共享模式中获取,忽略中断。
|
void |
acquireSharedInterruptibly(long arg)
获得在共享模式下,如果中断中止。
|
protected boolean |
compareAndSetState(long expect, long update)
自动设置同步状态的更新后的值,如果当前状态值等于期望值。
|
Collection<Thread> |
getExclusiveQueuedThreads()
返回一个包含可能等待在独占模式中获得的线程的集合。
|
Thread |
getFirstQueuedThread()
返回第一个(最长的等待队列中的线程),或
null如果没有线程当前排队。
|
Collection<Thread> |
getQueuedThreads()
返回一个包含可能等待获取的线程的集合。
|
int |
getQueueLength()
返回等待获取的线程数的估计值。
|
Collection<Thread> |
getSharedQueuedThreads()
返回一个包含可能等待在共享模式中获取的线程的集合。
|
protected long |
getState()
返回同步状态的当前值。
|
Collection<Thread> |
getWaitingThreads(AbstractQueuedLongSynchronizer.ConditionObject condition)
返回一个集合,可以在给定的条件下,与此相关的线程同步。
|
int |
getWaitQueueLength(AbstractQueuedLongSynchronizer.ConditionObject condition)
返回一个估计的线程数在给定的条件下,与此同步关联。
|
boolean |
hasContended()
查询是否有线程所主张获得同步;如果是一个获取方法曾受阻。
|
boolean |
hasQueuedPredecessors()
查询是否有任何线程等待获取比当前线程更长的时间。
|
boolean |
hasQueuedThreads()
查询是否有任何线程等待获取。
|
boolean |
hasWaiters(AbstractQueuedLongSynchronizer.ConditionObject condition)
查询是否有线程等待在给定的条件下,与此同步关联。
|
protected boolean |
isHeldExclusively()
返回
true如果同步举行专门就当前线程(调用)。
|
boolean |
isQueued(Thread thread)
如果给定线程当前正在排队,则返回真。
|
boolean |
owns(AbstractQueuedLongSynchronizer.ConditionObject condition)
查询是否给定的conditionobject使用同步器的锁。
|
boolean |
release(long arg)
独家发布模式。
|
boolean |
releaseShared(long arg)
共享模式中的版本。
|
protected void |
setState(long newState)
设置同步状态的值。
|
String |
toString()
返回一个字符串标识此同步器,以及其状态。
|
protected boolean |
tryAcquire(long arg)
尝试在独占模式下获得。
|
boolean |
tryAcquireNanos(long arg, long nanosTimeout)
试图在独占模式下获得的,如果不中止中断,如果给定的超时时间流逝。
|
protected long |
tryAcquireShared(long arg)
尝试在共享模式中获得。
|
boolean |
tryAcquireSharedNanos(long arg, long nanosTimeout)
试图在共享模式下获得的,如果不中止中断,如果给定的超时时间流逝。
|
protected boolean |
tryRelease(long arg)
试图设置状态以反映独占模式中的释放。
|
protected boolean |
tryReleaseShared(long arg)
试图设置状态以反映共享模式中的释放。
|
getExclusiveOwnerThread, setExclusiveOwnerThreadprotected AbstractQueuedLongSynchronizer()
AbstractQueuedLongSynchronizer实例。
protected final long getState()
volatile内存语义读。
protected final void setState(long newState)
volatile内存语义写。
newState -新的状态值
protected final boolean compareAndSetState(long expect,
long update)
volatile读写的内存语义。
expect -期望值
update -新价值
true如果成功。错误返回表示实际值不等于期望值。
protected boolean tryAcquire(long arg)
此方法总是由执行线程的线程调用的。如果此方法报告失败,则获取方法可以将该线程队列队列,如果它没有排队,直到它被另一些线程释放时发出信号。这可以用来实现方法Lock.tryLock()。
arg -获取参数。此值总是传递给获取方法的一个值,或者保存在一个条件等待的条件下的值。价值是另有解释,可以代表任何你喜欢的东西。
true如果成功。一旦成功,这个对象已被收购。
IllegalMonitorStateException如果获取将同步在非法状态。此异常必须以一致的方式被抛出,以同步正确工作。
UnsupportedOperationException如果独占模式不支持
protected boolean tryRelease(long arg)
此方法总是由线程执行释放调用。
arg -释放参数。此值总是一个传递给一个释放方法,或在进入一个条件等待时的当前状态值。价值是另有解释,可以代表任何你喜欢的东西。
true如果这个对象现在处于完全释放状态,所以任何等待的线程试图获取;否则,
false。
IllegalMonitorStateException如果释放将同步在非法状态。此异常必须以一致的方式被抛出,以同步正确工作。
UnsupportedOperationException如果独占模式不支持
protected long tryAcquireShared(long arg)
此方法总是由执行线程的线程调用的。如果此方法报告失败,则获取方法可以将该线程队列队列,如果它没有排队,直到它被另一些线程释放时发出信号。
arg -获取参数。此值总是传递给获取方法的一个值,或者保存在一个条件等待的条件下的值。价值是另有解释,可以代表任何你喜欢的东西。
IllegalMonitorStateException如果获取将同步在非法状态。此异常必须以一致的方式被抛出,以同步正确工作。
UnsupportedOperationException如果共享模式是不支持的
protected boolean tryReleaseShared(long arg)
此方法总是由线程执行释放调用。
arg -释放参数。此值总是一个传递给一个释放方法,或在进入一个条件等待时的当前状态值。价值是另有解释,可以代表任何你喜欢的东西。
true释放共享模式可以获得一等(共享或独占)成功;否则,
false
IllegalMonitorStateException如果释放将同步在非法状态。此异常必须以一致的方式被抛出,以同步正确工作。
UnsupportedOperationException如果共享模式是不支持的
protected boolean isHeldExclusively()
true如果同步举行专门就当前线程(调用)。这个方法被调用,在每次调用非等待
AbstractQueuedLongSynchronizer.ConditionObject方法。(等待方法调用
release(long)
默认实现将UnsupportedOperationException。这个方法调用内部只有在AbstractQueuedLongSynchronizer.ConditionObject方法,所以不需要被定义,如果没有使用条件。
true如果同步独家持有;
false否则
UnsupportedOperationException -如果不支持条件
public final void acquire(long arg)
tryAcquire(long)实施成功,返回。否则,线程队列,可能重复查封和解封,调用
tryAcquire(long)直到成功。这种方法可以用来实现方法
Lock.lock()。
arg -获取参数。这个值是给
tryAcquire(long)但另有解释,可以代表任何你喜欢的东西。
public final void acquireInterruptibly(long arg)
throws InterruptedException
tryAcquire(long),返回成功。否则,线程队列,可能重复查封和解封,调用
tryAcquire(long)直到成功或线程被中断。这种方法可以用来实现方法
Lock.lockInterruptibly()。
arg -获取参数。这个值是给
tryAcquire(long)但另有解释,可以代表任何你喜欢的东西。
InterruptedException -如果当前线程被中断
public final boolean tryAcquireNanos(long arg,
long nanosTimeout)
throws InterruptedException
tryAcquire(long),返回成功。否则,线程队列,可能重复查封和解封,调用
tryAcquire(long)直到成功或线程被中断或超时的逝去。这种方法可以用来实现方法
Lock.tryLock(long, TimeUnit)。
arg -获取参数。这个值是给
tryAcquire(long)但另有解释,可以代表任何你喜欢的东西。
nanosTimeout -纳秒的最大数量等
true如果获得;
false如果超时
InterruptedException -如果当前线程被中断
public final boolean release(long arg)
tryRelease(long)实现。这种方法可以用来实现方法
Lock.unlock()。
arg -释放参数。这个值是给
tryRelease(long)但另有解释,可以代表任何你喜欢的东西。
tryRelease(long)返回的值
public final void acquireShared(long arg)
tryAcquireShared(long)实施成功,返回。否则,线程队列,可能重复查封和解封,调用
tryAcquireShared(long)直到成功。
arg -获取参数。这个值是给
tryAcquireShared(long)但另有解释,可以代表任何你喜欢的东西。
public final void acquireSharedInterruptibly(long arg)
throws InterruptedException
tryAcquireShared(long),返回成功。否则,线程队列,可能重复查封和解封,调用
tryAcquireShared(long)直到成功或线程被中断。
arg -获取参数。这个值是给
tryAcquireShared(long)但另有解释,可以代表任何你喜欢的东西。
InterruptedException -如果当前线程被中断
public final boolean tryAcquireSharedNanos(long arg,
long nanosTimeout)
throws InterruptedException
tryAcquireShared(long),返回成功。否则,线程队列,可能重复查封和解封,调用
tryAcquireShared(long)直到成功或线程被中断或超时的逝去。
arg -获取参数。这个值是给
tryAcquireShared(long)但另有解释,可以代表任何你喜欢的东西。
nanosTimeout -纳秒的最大数量等
true如果获得;
false如果超时
InterruptedException -如果当前线程被中断
public final boolean releaseShared(long arg)
tryReleaseShared(long)实现。
arg -释放参数。这个值是给
tryReleaseShared(long)但另有解释,可以代表任何你喜欢的东西。
tryReleaseShared(long)返回的值
public final boolean hasQueuedThreads()
true返回不保证其他线程会获得。
在这个实现中,这种操作在恒定时间内返回。
true如果可能有其他线程等待获取
public final boolean hasContended()
在这个实现中,这种操作在恒定时间内返回。
true如果有过争
public final Thread getFirstQueuedThread()
null如果没有线程当前排队。
在这个实现中,该操作通常的回报,在固定的时间,但可以重复在争夺如果其他线程同时修改队列。
null如果没有线程当前排队
public final boolean isQueued(Thread thread)
这个实现遍历队列判断给定线程的存在。
thread -螺纹
true如果给定线程在队列中
NullPointerException -如果线程是无效的
public final boolean hasQueuedPredecessors()
这种方法的调用相当于(但可能比)更有效:
getFirstQueuedThread() != Thread.currentThread() &&
hasQueuedThreads()
注意,因为取消由于中断和超时可能发生在任何时间,一个true返回不保证其他线程将获得在当前线程。同样,经过此方法返回一个线程false赢得比赛将是可能的,因为队列是空的。
这种方法的设计是由一个公平的同步器,避免使用barging。这种同步器的tryAcquire(long)方法应该返回false,及其tryAcquireShared(long)方法应该返回一个负值,如果这个方法返回true(除非这是一个可获得)。例如,在tryAcquire方法公平、折返,独占模式同步可能看起来像这样:
protected boolean tryAcquire(int arg) {
if (isHeldExclusively()) {
// A reentrant acquire; increment hold count
return true;
} else if (hasQueuedPredecessors()) {
return false;
} else {
// try to acquire normally
}
}
true如果有排队线前面的当前线程,并
false如果当前线程在队列或队列的头部是空的
public final int getQueueLength()
public final Collection<Thread> getQueuedThreads()
public final Collection<Thread> getExclusiveQueuedThreads()
getQueuedThreads()除外,它只返回那些线程等待由于独家获得。
public final Collection<Thread> getSharedQueuedThreads()
getQueuedThreads()除外,它只返回那些线程等待,由于共同的获得。
public final boolean owns(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition -条件
true
NullPointerException -如果条件是空的
public final boolean hasWaiters(AbstractQueuedLongSynchronizer.ConditionObject condition)
true收益并不能保证未来的
signal将唤醒所有线程。这种方法的设计主要是用于监测系统状态。
condition -条件
true如果有任何等待的线程
IllegalMonitorStateException -如果不是独家同步举行
IllegalArgumentException -如果给定的条件是不是与此同步关联
NullPointerException -如果条件是空的
public final int getWaitQueueLength(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition -条件
IllegalMonitorStateException -如果不是独家同步举行
IllegalArgumentException -如果给定的条件是不是与此同步关联
NullPointerException -如果条件是空的
public final Collection<Thread> getWaitingThreads(AbstractQueuedLongSynchronizer.ConditionObject condition)
condition -条件
IllegalMonitorStateException -如果不是独家同步举行
IllegalArgumentException -如果给定的条件是不是与此同步关联
NullPointerException -如果条件是空的
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.