参考Thread.java,interrupt标记位是什么?
来源:5-5 中断信号

Ywandung_Lyou
2020-02-02
讲师好!
以下是从Thread.java
中截取的一段代码,我没有在源码中找到interrupt标记位是哪个变量,能帮忙找找吗?(っ´Ι`)っ
/** * Tests whether the current thread has been interrupted. The * <i>interrupted status</i> of the thread is cleared by this method. In * other words, if this method were to be called twice in succession, the * second call would return false (unless the current thread were * interrupted again, after the first call had cleared its interrupted * status and before the second call had examined it). * * <p>A thread interruption ignored because a thread was not alive * at the time of the interrupt will be reflected by this method * returning false. * * @return <code>true</code> if the current thread has been interrupted; * <code>false</code> otherwise. * @see #isInterrupted() * @revised 6.0 */ public static boolean interrupted() { return currentThread().isInterrupted(true); } /** * Tests whether this thread has been interrupted. The <i>interrupted * status</i> of the thread is unaffected by this method. * * <p>A thread interruption ignored because a thread was not alive * at the time of the interrupt will be reflected by this method * returning false. * * @return <code>true</code> if this thread has been interrupted; * <code>false</code> otherwise. * @see #interrupted() * @revised 6.0 */ public boolean isInterrupted() { return isInterrupted(false); } /** * Tests if some Thread has been interrupted. The interrupted state * is reset or not based on the value of ClearInterrupted that is * passed. */ private native boolean isInterrupted(boolean ClearInterrupted); /** * Throws {@link NoSuchMethodError}. * * @deprecated This method was originally designed to destroy this * thread without any cleanup. Any monitors it held would have * remained locked. However, the method was never implemented. * If if were to be implemented, it would be deadlock-prone in * much the manner of {@link #suspend}. If the target thread held * a lock protecting a critical system resource when it was * destroyed, no thread could ever access this resource again. * If another thread ever attempted to lock this resource, deadlock * would result. Such deadlocks typically manifest themselves as * "frozen" processes. For more information, see * <a href="{@docRoot}/../technotes/guides/concurrency/threadPrimitiveDeprecation.html"> * Why are Thread.stop, Thread.suspend and Thread.resume Deprecated?</a>. * @throws NoSuchMethodError always */
写回答
1回答
-
小伙伴很仔细,点赞。
interrupt标记位并不是一个在Java中变量,你可以看到有这行代码:
interrupt0(); // Just to set the interrupt flag
这是一个native方法:
private native void interrupt0();
是在更底层修改的。
012020-02-03
相似问题