Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>Thread.isInterrupted()</code> is a very cheap function to call. There a few more indirections but all calls are quick enough. To summarize:</p> <blockquote> <p>It must be possible for Java to emulate <code>Thread.currentThread().isInterrupted()</code> by performing the double indirection <code>Thread::current()-&gt;_osthread-&gt;_interrupted</code>.</p> </blockquote> <p><a href="http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/os/linux/vm/os_linux.cpp" rel="nofollow">Source</a>:</p> <pre><code>bool os::is_interrupted(Thread* thread, bool clear_interrupted) { assert(Thread::current() == thread || Threads_lock-&gt;owned_by_self(), "possibility of dangling Thread pointer"); OSThread* osthread = thread-&gt;osthread(); bool interrupted = osthread-&gt;interrupted(); if (interrupted &amp;&amp; clear_interrupted) { osthread-&gt;set_interrupted(false); // consider thread-&gt;_SleepEvent-&gt;reset() ... optional optimization } return interrupted; } </code></pre> <p><a href="http://hg.openjdk.java.net/jdk8/jdk8/hotspot/file/tip/src/share/vm/runtime/osThread.hpp" rel="nofollow"><code>OSThread</code></a> is implemented like this:</p> <pre><code>volatile jint _interrupted; // Thread.isInterrupted state // Note: _interrupted must be jint, so that Java intrinsics can access it. // The value stored there must be either 0 or 1. It must be possible // for Java to emulate Thread.currentThread().isInterrupted() by performing // the double indirection Thread::current()-&gt;_osthread-&gt;_interrupted. .... volatile bool interrupted() const { return _interrupted != 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload