来自public javadoc:
void blockedOn(Thread t, Interruptible b)
设置线程的阻止字段。
我在java nio研究期间使用该方法进行了堆栈,特别是AbstractInterruptibleChannel源代码
答案 0 :(得分:1)
如果查看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;
}
}
这用于在线程中断时触发操作。
答案 1 :(得分:0)
好像,我确实在java.lang.Thread源代码(Oracle / Sun JVM)中找到了答案:
/* 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;
}
}
public void interrupt() {
if (this != Thread.currentThread())
checkAccess();
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
interrupt0(); // Just to set the interrupt flag
b.interrupt();
return;
}
}
interrupt0();
}
如果我错了,请纠正我,我的结论是: