- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在await AQS的方法(AbstractQueuedSynchronizer):我想知道 while (!isOnSyncQueue(node)) {
while
的含义
我觉得如果这个节点正常被唤醒(没有被中断),肯定会在另一个线程执行完signal方法后移到sync队列,然后在另一个线程执行unlock方法唤醒.
所以可能会出现节点正常唤醒,但不在同步队列中的情况?如果那不可能,我认为应该在这里使用 if
而不是 while
public final void await() throws InterruptedException {
if (Thread.interrupted())
throw new InterruptedException();
Node node = addConditionWaiter();
int savedState = fullyRelease(node);
int interruptMode = 0;
while (!isOnSyncQueue(node)) {
LockSupport.park(this);
if ((interruptMode = checkInterruptWhileWaiting(node)) != 0)
break;
}
if (acquireQueued(node, savedState) && interruptMode != THROW_IE)
interruptMode = REINTERRUPT;
if (node.nextWaiter != null) // clean up if cancelled
unlinkCancelledWaiters();
if (interruptMode != 0)
reportInterruptAfterWait(interruptMode);
}
最佳答案
唤醒有两种形式。通常的种类和spurious种类。这段代码:
while (!isOnSyncQueue(node)) {
...
}
一直循环直到 isOnSyncQueue(node)
返回 false
并且是 while
而不是 if
,因为唤醒可能是虚假的,而不是因为正在等待的条件已经发生。
关于java - 为什么在AQS(AbstractQueuedSynchronizer)的await方法中使用 "while",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63563728/
聊聊JUC包下的底层支撑类-AbstractQueuedSynchronizer(AQS) juc包下的一堆并发工具类是我们日常开发特别是面试中常被拿来问的八股文之一,为了工作也好,为了面试也
在await AQS的方法(AbstractQueuedSynchronizer):我想知道 while (!isOnSyncQueue(node)) { 中 while 的含义 我觉得如果这个节点正
我正在查看 java.uti.concurrent.locks.AbstractQueuedSynchronizer 的源代码,acquire() 方法看起来像这样 - public final v
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我正在实现一个自定义的 FutureTask (未扩展)以在线程池等中使用。我需要特殊功能,并且无法直接扩展 FutureTask 的方法。为了帮助我做到这一点,我查看了默认实现。如果您无法访问代码,
我编写了一个使用 AbstractQueuedSynchronizer 的简单类。我写了一个代表“门”的类,如果打开则可以通过,如果关闭则阻塞。这是代码: public class GateBlock
大佬们,谁能给个LockSupport & AbstractQueuedSynchronizer的简单实用例子? javadocs 中给出的示例很紧张。 我理解 Semaphore 许可的使用。 感谢
我知道一些关于 AbstractQueuedSynchronizer 的细节。它是一个用于创建状态依赖类或同步器的框架。但是我没有得到在 ThreadPoolExecutor 的 Worker 中扩展
我试图从较高的层次理解 java 的并发 API 是如何使用 AbstractQueuedSynchronizer 作为构建 block 构建的。我在这个类中没有看到任何synchronized、wa
我无法弄清楚为什么几个“ajp-nio-8009-exec-XX”类型的线程被阻止。典型的线程转储堆栈跟踪如下所示: at sun.misc.Unsafe.park(Native Method)
我是一名优秀的程序员,十分优秀!