Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Jeff Higgins Newsgroups: comp.lang.java.programmer Subject: Re: javax.swing.Timer blocking program termination Date: Tue, 14 Jul 2015 15:17:35 -0400 Organization: A noiseless patient Spider Lines: 32 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 14 Jul 2015 19:19:51 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e164d158183579609bf09837dee5210"; logging-data="11112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18viIauMB/frhxvBTwZAE3CVQHoANNckaU=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 In-Reply-To: Cancel-Lock: sha1:RcZ+Dc5u1G63IYTlJEZ3AMPfy1k= Xref: csiph.com comp.lang.java.programmer:32019 On 07/14/2015 02:35 PM, Martin Gregorie wrote: > IOW, could the timer have fired its event > before the default close operation had been defined and would the timer > event have been ignored if it fired its event before the JFrame had been > completed and displayed? > Well, in the code Knute supplied in his original post the timer isn't started until after the call to setVisible(true). The timer is a repeating timer - it continues to fire events at the delay rate. I guess that at a rate of more than one per second the ThreadQueue (or whatever the controlling mechanism) thinks there is work remaining to be done and will not allow the EDT to shut down. Conversely, at a rate less than one per second this mechanism thinks all work is done and the EDT is allowed to expire. Shrug. public class test extends JFrame { public test() { Timer timer = new Timer(1000,event -> {}); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setSize(400,300); setVisible(true); timer.start(); } public static void main(String... args) { EventQueue.invokeLater(() -> new test()); }}