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