来自公共javadoc:
void blockedOn(线程t,可中断b)
设置线程的阻止程序字段。
在java nio研究期间,我使用该方法进行了堆栈,特别是AbstractInterruptibleChannel源代码。
发布于 2011-12-17 13:11:09
如果您查看它调用的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;
}
}这用于在线程被中断时触发操作。
发布于 2011-12-17 13:00:39
似乎,我在java.lang.Thread源代码(Oracle)中找到了答案:
/* 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();
}所以如果我错了,我的结论是:
sun.misc.SharedSecrets.getJavaLangAccess().blockedOn(threadInstance,intrInstance);只对线程中断事件
https://stackoverflow.com/questions/8544891
复制相似问题