Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: What is so bad aboud Thread.stop() ? Date: Thu, 01 Aug 2013 10:01:42 -0700 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: <8fe57dc2-a323-4821-941c-4036663cbce5@googlegroups.com> <51f9df70$0$52766$742ec2ed@news.sonic.net> <7bf3ea0e-533b-4cfe-a85d-ad75b5d3657c@googlegroups.com> <51fa7dea$0$298$14726298@news.sunsite.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 1 Aug 2013 16:55:11 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="fba3415ba68d85d643935af2f52f0b4b"; logging-data="3978"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Gjzq64E+0gnEwH5MMioUVE5YRw8pmG+k=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 In-Reply-To: Cancel-Lock: sha1:l5VsxXhWZS1Emt6X4hrs1FbF7F4= Xref: csiph.com comp.lang.java.programmer:24873 On 8/1/2013 9:30 AM, taqmcg@gmail.com wrote: > Sure... If you control all the code, and your code has no bugs in it > (so that no infinite loop occurs somewhere you didn't expect). > That's not always the case -- I certainly expect that my code has > bugs and I use a fair number of external libraries which may have > bugs of there own. Well, the better option is to use a library without major bugs that require Thread.stop(). Numerical libraries are fairly common, can you find one that doesn't hang? Another better option is to use Thread.interrupt(). That's a flag defined for you in the system and checked often by many system libraries. It's a clean way of stopping a thread. Another better option is to decompile the library code (not hard for byte code, somewhat hard for machine code) and insert a check for Thread.interrupt() or some other flag or condition, so that you don't need to use Thread.stop(). But yes it's possible to use Thread.stop() in extremis. I wouldn't though. Use System.exit() instead, if things have really gone that far off the rails. Better to cleanly shutdown the JVM than risk weird bugs or whatnot. However, see the "find a less buggy library" option up top.