Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8232676

Thread.isInterrupted() always returns false after thread termination

    Details

    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      Hide
      The only functional compatibility risk here is if code were to interrupt threads before they were started and not be prepared for the interrupt to take affect once the thread is started.

      If code tests the current Hotspot behaviour then it would of course also need to be updated.
      Show
      The only functional compatibility risk here is if code were to interrupt threads before they were started and not be prepared for the interrupt to take affect once the thread is started. If code tests the current Hotspot behaviour then it would of course also need to be updated.
    • Interface Kind:
      Java API
    • Scope:
      JDK

      Description

      Summary

      Update the java.lang.Thread specification in regards to interruption happening while a thread is not alive, to account for a new implementation that tracks the interrupted state at all times in the thread lifecycle.

      Problem

      The specification for java.lang.Thread::interrupt allows for thread interruption to be a no-op if the thread is not alive:

      Interrupting a thread that is not alive need not have any effect.

      and the Thread::interrupted and Thread::isInterrupted method reflect the behaviour of the Hotspot VM by stating:

      A thread interruption ignored because a thread was not alive at the time of the interrupt will be reflected by this method returning false.

      With the new implementation of the interrupted state an accurate record of the interrupt state of a thread is available at all times in the thread's lifecycle and so these parts of the specification are no longer correct.

      Solution

      We can remove the statements about returning false; and we can add an implementation note that interruption while a thread is not alive is not ignored.

      Specification

      For Thread::interrupt add:

      * @implNote In this implementation, interruption of a thread that is not
      * alive still records the interrupt request was made and will report it
      * via {@link #interrupted} and {@link #isInterrupted()}.

      For Thread::interrupted and Thread::isInterrupted delete:

       * <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.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dholmes David Holmes
                Reporter:
                martin Martin Buchholz
                Reviewed By:
                Alan Bateman, Daniel Daugherty, Doug Lea, Martin Buchholz
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: