从公共javadoc:
void blockedOn(Thread t, Interruptible b)
设置线程的阻止者字段。
我在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/