JDK-6194515 : Thread.isInterrupted() returns true for stopped threads
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-12
  • Updated: 2010-08-03
  • Resolved: 2005-10-25
Related Reports
Relates :  
Description
A licnesee finds out there is a case Thread.isInterrupted() for a stopped thread 
returns true.
They requested that should be mentioned explicitly in Thread API document.

When a thread, which stopped by another thread,  checks  by Thread.isInterrupted()
whether there happens interruption , the return value is true.

REPRODUCE :
 1) Compile the attached test case
   
---- Test Case ---
public class test2 {
   public static void main(String[] args) throws Exception {
      sub t = new sub();

      t.start();
      System.out.println("Press key");
      System.in.read();

      System.out.println("stop");
      t.stop();

      while (t.enter) {
      }

      System.out.println("join");
      t.join();
   }

}

class sub extends Thread{
   static volatile boolean enter = false;
   public void run() {
       System.out.println("before stop isInterrupted = "+Thread.currentThread().isInterrupted());

       enter = true;
       try {
         while(true) 
          ;
       }
       catch(Throwable e) {
           System.out.println("after stop isInterrupted = "+Thread.currentThread().isInterrupted());
       }

       System.out.println("end");
       enter = false;
   }
}
-----------------


  2) Launch "java test2"
  3) You will be asked to enter. Press "enter"
  
The messages are,

K:\shares2\thread-stop-isinterupted-strange>java test2
Press key
before stop isInterrupted = false
                                               <== Press "enter"
stop
after stop isInterrupted = true                <= This shows the return value.
end
join

CONFIGURATION :
   OS : WindowsXP(SP1, Japanese)
   JRE: 1.4.2/5.0/6.0b11

###@###.### 2004-11-12 05:56:35 GMT

Comments
EVALUATION see comments
25-10-2005