gpt4 book ai didi

java - JavaLangAccess.blockedOn(Thread t, Interruptible b) 是做什么的?

转载 作者:太空宇宙 更新时间:2023-11-04 08:25:57 25 4
gpt4 key购买 nike

来自公共(public) javadoc:

void blockedOn(Thread t, Interruptible b)

Set thread's blocker field.

我在 java nio 研究期间确实使用了该方法,特别是 AbstractInterruptibleChannel 源代码

最佳答案

如果你看看 OpenJDK 它调用

/* The object in which this thread is blocked in an interruptible I/O
* operation, if any. The blocker's interrupt method should be invoked
* after setting this thread's interrupt status.
*/
private volatile Interruptible blocker;
private Object blockerLock = new Object();

/* Set the blocker field; invoked via sun.misc.SharedSecrets from java.nio code
*/
void blockedOn(Interruptible b) {
synchronized (blockerLock) {
blocker = b;
}
}

这用于在线程中断时触发操作。

关于java - JavaLangAccess.blockedOn(Thread t, Interruptible b) 是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8544891/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com