Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: How do I automatically cleanly terminate a thread? Date: Mon, 17 Jul 2017 11:53:47 -0500 Organization: A noiseless patient Spider Lines: 19 Message-ID: References: <23395a95-7741-4c12-bb16-bb50341df864@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 17 Jul 2017 16:49:52 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="ed19dde6d4eefd924907c4d9bf7f7ff0"; logging-data="20676"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tXCU4TfaO0bVrrIIEjDhs" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: <23395a95-7741-4c12-bb16-bb50341df864@googlegroups.com> Content-Language: en-US Cancel-Lock: sha1:3nZw42JcMqFVCOdZ1ua1CZLoUWY= Xref: csiph.com comp.lang.java.programmer:36960 On 7/17/2017 11:03, Eric Douglas wrote: > On Monday, July 17, 2017 at 11:27:46 AM UTC-4, Eric Sosman wrote: >> If all you need is that the thread goes away in order to allow the >> JVM to terminate, it may be simplest to make it a daemon: Call its >> setDaemon(true) method before calling start(). The JVM assumes that >> it's all right to clobber daemon threads when shutting down, the idea >> being that if the asynchronous shutdown causes corruption it won't >> matter because the whole Java environment is about to disappear. >> > > So my main thread kicks off this process from a JButton action. I declared it a daemon thread and it did auto terminate when the last GUI object was destroyed without calling it's proper close method. That thread was sitting on the take() method and it printing something in the InterruptedException section which never printed. So if we let the JVM terminate it with the daemons can I assume that's ok on a method like this? > Why don't you interrupt the thread as part of the shutdown process and then it will print your message in the catch section. -- Knute Johnson