Re: What is so bad aboud Thread.stop() ?
On 01/08/13 22:07, Lew wrote:
usvirtualo...@gmail.com wrote:
Lew wrote:
Who will catch the exception?
The code being stopped. E.g., I could have my
thread defined in a class Z like:
class Z implements Runnable {
public void run() {
try {
... code
} catch (ThreadDeath e) {
Since this catch is in the same thread that just died, it cannot run.
Are you saying that this won't print out "Dead"?
public class Stopped {
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
public void run() {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
System.out.println("Interrupted");
} catch (ThreadDeath td) {
System.out.println("Dead");
}
}
};
t.start();
Thread.sleep(4000);
System.out.println("Stopping");
t.stop();
}
}
I get:
Stopping
Dead
--
ss at comp dot lancs dot ac dot uk