Path: csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: javax.swing.Timer blocking program termination Date: Mon, 13 Jul 2015 16:03:53 -0700 Organization: A noiseless patient Spider Lines: 39 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Mon, 13 Jul 2015 23:02:26 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="e4bb2c7dad0e79edbbf184ec68513a50"; logging-data="7725"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xEeBU4+rSrCTvWbBD+XG/" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 X-Mozilla-News-Host: news://news.eternal-september.org:119 Cancel-Lock: sha1:UtYgeduHlcDgchlabuau20wk93g= Xref: csiph.com comp.lang.java.programmer:31994 So I have this program that uses a couple of javax.swing.Timers. I forgot to put in code to stop one of the timers yet the program would still terminate. I have set the default close operation for the frame to be DISPOSE_ON_CLOSE. What I found was that a timer of less the 1000ms would prevent an application based on a JFrame from stopping but 1000ms or more and it would stop just fine. I know that javax.swing.Timer uses a common thread for all timers but I don't see anywhere that describes the stopping behavior. The program below will stop if the JFrame is closed and the timer is 1000ms or greater but hang if it is less. I would be really curious to know if somebody else can duplicate this. import java.awt.*; import java.awt.event.*; import javax.swing.*; 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()); } } Thanks, -- Knute Johnson