Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!newsfeed.CARNet.hr!garrison.bnet.hr!gregory.BNet.hr!not-for-mail From: Josip Almasi Newsgroups: comp.lang.java.programmer Subject: Re: refusal to quit Date: Tue, 02 Sep 2014 10:49:14 +0200 Organization: B.net Hrvatska d.o.o. Lines: 35 Message-ID: References: <7lo90apm56ne18c2fl7nk2o2adqghe0mkq@4ax.com> NNTP-Posting-Host: 188.252.185.114 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: gregory.bnet.hr 1409647755 4171 188.252.185.114 (2 Sep 2014 08:49:15 GMT) X-Complaints-To: abuse@globalnet.hr NNTP-Posting-Date: Tue, 2 Sep 2014 08:49:15 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 In-Reply-To: <7lo90apm56ne18c2fl7nk2o2adqghe0mkq@4ax.com> Xref: csiph.com comp.lang.java.programmer:29889 On 09/01/2014 11:20 PM, Roedy Green wrote: > On Fri, 29 Aug 2014 09:56:45 -0700, Roedy Green > wrote, quoted or indirectly quoted > someone who said : > >> Sometimes programs simply refuse to quit after main has terminated. > > I sprinkled a call to this code in every main. ... > In one case it said that a Timer was still running. I thought > Timer.cancel would be sufficient to kill it, but apparently not. > I gather it just stops the periodic calls to run, but leaves the > thread alive. Now that's funny. Check this: public void cancel() { synchronized(queue) { thread.newTasksMayBeScheduled = false; queue.clear(); queue.notify(); // In case queue was already empty. } } So it just wakes up all threads and will not run them again. Since queue is private, I suppose only thread waiting for it may be inner TimerThread. Main loop terminates allright, but that's it. What really happens depends on TimerTask.run() implementation. BTW mainLoop() catches InterruptedException and ignores it. Regards...