本文整理了Java中com.google.common.util.concurrent.Monitor.signalNextWaiter()
方法的一些代码示例,展示了Monitor.signalNextWaiter()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Monitor.signalNextWaiter()
方法的具体详情如下:
包路径:com.google.common.util.concurrent.Monitor
类名称:Monitor
方法名:signalNextWaiter
[英]Signals some other thread waiting on a satisfied guard, if one exists.
We manage calls to this method carefully, to signal only when necessary, but never losing a signal, which is the classic problem of this kind of concurrency construct. We must signal if the current thread is about to relinquish the lock and may have changed the state protected by the monitor, thereby causing some guard to be satisfied.
In addition, any thread that has been signalled when its guard was satisfied acquires the responsibility of signalling the next thread when it again relinquishes the lock. Unlike a normal Condition, there is no guarantee that an interrupted thread has not been signalled, since the concurrency control must manage multiple Conditions. So this method must generally be called when waits are interrupted.
On the other hand, if a signalled thread wakes up to discover that its guard is still not satisfied, it does not need to call this method before returning to wait. This can only happen due to spurious wakeup (ignorable) or another thread acquiring the lock before the current thread can and returning the guard to the unsatisfied state. In the latter case the other thread (last thread modifying the state protected by the monitor) takes over the responsibility of signalling the next waiter.
This method must not be called from within a beginWaitingFor/endWaitingFor block, or else the current thread's guard might be mistakenly signalled, leading to a lost signal.
[中]如果有一个线程在等待一个满意的守卫(如果有的话)的话,它会向其他线程发出信号。
我们谨慎地管理对这种方法的调用,只在必要时发出信号,但绝不会丢失信号,这是这种并发结构的典型问题。我们必须发出信号,表明当前线程是否即将放弃锁,并且可能已经更改了监视器保护的状态,从而导致满足某些保护要求。
此外,任何在其保护满意时发出信号的线程,都将在下一个线程再次放弃锁时获得发出信号的责任。与正常情况不同,不能保证中断的线程没有收到信号,因为并发控制必须管理多个情况。因此,当等待被中断时,通常必须调用此方法。
另一方面,如果一个有信号的线程醒来发现它的保护仍然不满足,那么它在返回等待之前不需要调用这个方法。这只能是由于虚假唤醒(可忽略)或另一个线程在当前线程启动并将保护返回到不满意状态之前获取锁而导致的。在后一种情况下,另一个线程(修改监视器保护状态的最后一个线程)负责向下一个服务生发送信号。
不能从beginWaitingFor/endWaitingFor块内调用此方法,否则可能会错误地向当前线程的保护发送信号,导致信号丢失。
代码示例来源:origin: google/guava
/** Leaves this monitor. May be called only by a thread currently occupying this monitor. */
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: wildfly/wildfly
/** Leaves this monitor. May be called only by a thread currently occupying this monitor. */
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: google/guava
@GuardedBy("lock")
private void await(Guard guard, boolean signalBeforeWaiting) throws InterruptedException {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.await();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: google/guava
signalNextWaiter();
代码示例来源:origin: google/guava
/** Caller should check before calling that guard is not satisfied. */
@GuardedBy("lock")
private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
throws InterruptedException {
boolean firstTime = true;
try {
do {
if (nanos <= 0L) {
return false;
}
if (firstTime) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
firstTime = false;
}
nanos = guard.condition.awaitNanos(nanos);
} while (!guard.isSatisfied());
return true;
} finally {
if (!firstTime) {
endWaitingFor(guard);
}
}
}
}
代码示例来源:origin: google/guava
@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.awaitUninterruptibly();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: wildfly/wildfly
@GuardedBy("lock")
private void await(Guard guard, boolean signalBeforeWaiting) throws InterruptedException {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.await();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: google/j2objc
/** Caller should check before calling that guard is not satisfied. */
@GuardedBy("lock")
private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
throws InterruptedException {
boolean firstTime = true;
try {
do {
if (nanos <= 0L) {
return false;
}
if (firstTime) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
firstTime = false;
}
nanos = guard.condition.awaitNanos(nanos);
} while (!guard.isSatisfied());
return true;
} finally {
if (!firstTime) {
endWaitingFor(guard);
}
}
}
}
代码示例来源:origin: google/j2objc
@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.awaitUninterruptibly();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: wildfly/wildfly
signalNextWaiter();
代码示例来源:origin: wildfly/wildfly
/** Caller should check before calling that guard is not satisfied. */
@GuardedBy("lock")
private boolean awaitNanos(Guard guard, long nanos, boolean signalBeforeWaiting)
throws InterruptedException {
boolean firstTime = true;
try {
do {
if (nanos <= 0L) {
return false;
}
if (firstTime) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
firstTime = false;
}
nanos = guard.condition.awaitNanos(nanos);
} while (!guard.isSatisfied());
return true;
} finally {
if (!firstTime) {
endWaitingFor(guard);
}
}
}
}
代码示例来源:origin: wildfly/wildfly
@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.awaitUninterruptibly();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: com.google.guava/guava-jdk5
/**
* Leaves this monitor. May be called only by a thread currently occupying this monitor.
*/
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby
/**
* Leaves this monitor. May be called only by a thread currently occupying this monitor.
*/
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger
/** Leaves this monitor. May be called only by a thread currently occupying this monitor. */
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/** Leaves this monitor. May be called only by a thread currently occupying this monitor. */
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: com.diffplug.guava/guava-concurrent
/**
* Leaves this monitor. May be called only by a thread currently occupying this monitor.
*/
public void leave() {
final ReentrantLock lock = this.lock;
try {
// No need to signal if we will still be holding the lock when we return
if (lock.getHoldCount() == 1) {
signalNextWaiter();
}
} finally {
lock.unlock(); // Will throw IllegalMonitorStateException if not held
}
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.guava
@GuardedBy("lock")
private void await(Guard guard, boolean signalBeforeWaiting)
throws InterruptedException {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.await();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: com.google.guava/guava-jdk5
@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.awaitUninterruptibly();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
@GuardedBy("lock")
private void awaitUninterruptibly(Guard guard, boolean signalBeforeWaiting) {
if (signalBeforeWaiting) {
signalNextWaiter();
}
beginWaitingFor(guard);
try {
do {
guard.condition.awaitUninterruptibly();
} while (!guard.isSatisfied());
} finally {
endWaitingFor(guard);
}
}
内容来源于网络,如有侵权,请联系作者删除!