Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: What is so bad aboud Thread.stop() ? Date: Thu, 01 Aug 2013 23:15:23 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: References: <8fe57dc2-a323-4821-941c-4036663cbce5@googlegroups.com> <51f93cc4$0$291$14726298@news.sunsite.dk> <699768ec-b0b7-4752-a373-b58b8a39e32e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx05.eternal-september.org; posting-host="a427a45ca9c98f260dc55db57379329b"; logging-data="23478"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uJMVpqofySYxe35L2yDGpoxJBtmuLCMw=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 In-Reply-To: Cancel-Lock: sha1:vah9sR0bLgEDm5YNZIYB6zbCjnY= Xref: csiph.com comp.lang.java.programmer:24877 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