< prev index next >
src/java.base/share/classes/java/lang/Thread.java
Print this page
*** 152,161 ****
--- 152,164 ----
private int priority;
/* Whether or not the thread is a daemon thread. */
private boolean daemon = false;
+ /* Interrupt state of the thread - read/written directly by JVM */
+ private volatile boolean interrupted;
+
/* Fields reserved for exclusive use by the JVM */
private boolean stillborn = false;
private long eetop;
/* What will be run. */
*** 969,1000 ****
* <p> If none of the previous conditions hold then this thread's interrupt
* status will be set. </p>
*
* <p> Interrupting a thread that is not alive need not have any effect.
*
* @throws SecurityException
* if the current thread cannot modify this thread
*
! * @revised 6.0
* @spec JSR-51
*/
public void interrupt() {
if (this != Thread.currentThread()) {
checkAccess();
// thread may be blocked in an I/O operation
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
! interrupt0(); // set interrupt status
b.interrupt(this);
return;
}
}
}
!
! // set interrupt status
interrupt0();
}
/**
* Tests whether the current thread has been interrupted. The
--- 972,1008 ----
* <p> If none of the previous conditions hold then this thread's interrupt
* status will be set. </p>
*
* <p> Interrupting a thread that is not alive need not have any effect.
*
+ * @implNote In the JDK Reference Implementation, interruption of a thread
+ * that is not alive still records that the interrupt request was made and
+ * will report it via {@link #interrupted} and {@link #isInterrupted()}.
+ *
* @throws SecurityException
* if the current thread cannot modify this thread
*
! * @revised 6.0, 14
* @spec JSR-51
*/
public void interrupt() {
if (this != Thread.currentThread()) {
checkAccess();
// thread may be blocked in an I/O operation
synchronized (blockerLock) {
Interruptible b = blocker;
if (b != null) {
! interrupted = true;
! interrupt0(); // inform VM of interrupt
b.interrupt(this);
return;
}
}
}
! interrupted = true;
! // inform VM of interrupt
interrupt0();
}
/**
* Tests whether the current thread has been interrupted. The
*** 1002,1050 ****
* 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} if the current thread has been interrupted;
* {@code false} 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} if this thread has been interrupted;
* {@code false} 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.
- */
- @HotSpotIntrinsicCandidate
- private native boolean isInterrupted(boolean ClearInterrupted);
-
- /**
* Tests if this thread is alive. A thread is alive if it has
* been started and has not yet died.
*
* @return {@code true} if this thread is alive;
* {@code false} otherwise.
--- 1010,1051 ----
* 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).
*
* @return {@code true} if the current thread has been interrupted;
* {@code false} otherwise.
* @see #isInterrupted()
! * @revised 6.0, 14
*/
public static boolean interrupted() {
! Thread t = currentThread();
! boolean interrupted = t.interrupted;
! // We may have been interrupted the moment after we read the field,
! // so only clear the field if we saw that it was set and will return
! // true; otherwise we could lose an interrupt.
! if (interrupted) {
! t.interrupted = false;
! clearInterruptEvent();
! }
! return interrupted;
}
/**
* Tests whether this thread has been interrupted. The <i>interrupted
* status</i> of the thread is unaffected by this method.
*
* @return {@code true} if this thread has been interrupted;
* {@code false} otherwise.
* @see #interrupted()
! * @revised 6.0, 14
*/
public boolean isInterrupted() {
! return interrupted;
}
/**
* Tests if this thread is alive. A thread is alive if it has
* been started and has not yet died.
*
* @return {@code true} if this thread is alive;
* {@code false} otherwise.
*** 2078,2084 ****
--- 2079,2086 ----
private native void setPriority0(int newPriority);
private native void stop0(Object o);
private native void suspend0();
private native void resume0();
private native void interrupt0();
+ private static native void clearInterruptEvent();
private native void setNativeName(String name);
}
< prev index next >