This behavior exists on Solaris 2.5.1, jdk1.1_Final (not tested on other
platforms, although I suspect it is more of a design flaw rather
than a platform bug.)
Once stop() is called on a Thread, isAlive() returns false although
the thread continues to run (it has a catch block).
Subsequent calls to stop() on the same Thread have no effect whatsoever.
stop() should attempt to stop any thread which is actually running.
(additionally this is not documented well and is different from interrupt(),
which has effect whenever called.)
Sample output:
> java TSBug
Thread[Thread-4,5,main] is alive? true
Thread[Thread-4,5,main] is alive? false
stopped with java.lang.ThreadDeath
Thread[Thread-4,5,main] is very much alive!
Thread[Thread-4,5,main] is alive? false
slept comfortably.
Thread[Thread-4,5,main] is very much alive!
Thread[Thread-4,5,main] is alive? false
slept comfortably.
Thread[Thread-4,5,main] is very much alive!
Input code:
class TSBug implements Runnable {
public void run(){
for(int i=0;i<3;i++){
try{
Thread.sleep(2000);
System.err.println("slept comfortably.");
} catch(Throwable t){
System.err.println("stopped with "+t);
}
System.err.println(Thread.currentThread()+" is very much alive!");
}
}
public static void main(String[] args) throws Exception {
Thread t = new Thread(new TSBug());
t.start();
System.err.println(t+" is alive? "+t.isAlive());
for(int i=0;i<3;i++){
Thread.sleep(1000);
t.stop();
System.err.println(t+" is alive? "+t.isAlive());
}
}
}
platforms, although I suspect it is more of a design flaw rather
than a platform bug.)
Once stop() is called on a Thread, isAlive() returns false although
the thread continues to run (it has a catch block).
Subsequent calls to stop() on the same Thread have no effect whatsoever.
stop() should attempt to stop any thread which is actually running.
(additionally this is not documented well and is different from interrupt(),
which has effect whenever called.)
Sample output:
> java TSBug
Thread[Thread-4,5,main] is alive? true
Thread[Thread-4,5,main] is alive? false
stopped with java.lang.ThreadDeath
Thread[Thread-4,5,main] is very much alive!
Thread[Thread-4,5,main] is alive? false
slept comfortably.
Thread[Thread-4,5,main] is very much alive!
Thread[Thread-4,5,main] is alive? false
slept comfortably.
Thread[Thread-4,5,main] is very much alive!
Input code:
class TSBug implements Runnable {
public void run(){
for(int i=0;i<3;i++){
try{
Thread.sleep(2000);
System.err.println("slept comfortably.");
} catch(Throwable t){
System.err.println("stopped with "+t);
}
System.err.println(Thread.currentThread()+" is very much alive!");
}
}
public static void main(String[] args) throws Exception {
Thread t = new Thread(new TSBug());
t.start();
System.err.println(t+" is alive? "+t.isAlive());
for(int i=0;i<3;i++){
Thread.sleep(1000);
t.stop();
System.err.println(t+" is alive? "+t.isAlive());
}
}
}
- duplicates
-
JDK-4241041 runnung thread is not alive after stop()
- Closed
-
JDK-4314342 Mechanism for Thread.stop broken. Sparc, compilers 1 and 2.
- Closed