Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.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 16:09:47 -0400 Organization: A noiseless patient Spider Lines: 157 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 20:12:03 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e164d158183579609bf09837dee5210"; logging-data="23343"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GJsB/fbKF3PifV+XsZmL6FeMvpR15Mqk=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 In-Reply-To: Cancel-Lock: sha1:Sfo5Igjnw7zEcK+qi3g7YYgzUzo= Xref: csiph.com comp.lang.java.programmer:32023 On 07/14/2015 02:35 PM, Martin Gregorie wrote: > On Tue, 14 Jul 2015 10:55:20 -0400, Jeff Higgins wrote: > >> Makes perfect sense to me. >> But I'm still not sure how a <1 sec timer keeps the EDT alive while a >1 >> sec timer doesn't - barring explicit stops in windowClosing. >> > > It occurs to me that, the way Knute's original example works, that he > might have inadvertently set up a race condition because all the heavy > lifting involved in setting up the JFrame, i.e. loading a shedload of > classes and constructing instances from them all happens on the EDT and > that this might well take a second or so to complete and still be running > when the timer gets started. 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? > > Of course, this may be a stupid idea, but it does fit the test results > which show a short timeout being ignored while a longer one does what > you'd expect. > > Here's a thread dump. don't know what it means. Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode): "TimerQueue" #14 daemon prio=5 os_prio=0 tid=0x0000000001b55000 nid=0x1159 runnable [0x00007fd462759000] java.lang.Thread.State: RUNNABLE at java.lang.Thread.currentThread(Native Method) at java.lang.Thread.interrupted(Thread.java:944) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.checkInterruptWhileWaiting(AbstractQueuedSynchronizer.java:2002) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2079) at java.util.concurrent.DelayQueue.take(DelayQueue.java:223) at javax.swing.TimerQueue.run(TimerQueue.java:171) at java.lang.Thread.run(Thread.java:745) "DestroyJavaVM" #13 prio=5 os_prio=0 tid=0x00007fd4641e2000 nid=0x114a waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "AWT-EventQueue-0" #11 prio=6 os_prio=0 tid=0x00007fd464214800 nid=0x1158 waiting on condition [0x00007fd46285a000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000000f5b76630> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) at java.awt.EventQueue.getNextEvent(EventQueue.java:547) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:170) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82) "AWT-Shutdown" #12 prio=5 os_prio=0 tid=0x00007fd464212800 nid=0x1157 in Object.wait() [0x00007fd46295b000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000000f5b76fe8> (a java.lang.Object) at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:314) - locked <0x00000000f5b76fe8> (a java.lang.Object) at java.lang.Thread.run(Thread.java:745) "AWT-XAWT" #10 daemon prio=6 os_prio=0 tid=0x00007fd464210800 nid=0x1156 runnable [0x00007fd462a5c000] java.lang.Thread.State: RUNNABLE at sun.awt.X11.XToolkit.waitForEvents(Native Method) at sun.awt.X11.XToolkit.run(XToolkit.java:568) at sun.awt.X11.XToolkit.run(XToolkit.java:532) at java.lang.Thread.run(Thread.java:745) "Java2D Disposer" #8 daemon prio=10 os_prio=0 tid=0x00007fd4641eb000 nid=0x1155 in Object.wait() [0x00007fd468111000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000000f5b5b918> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x00000000f5b5b918> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at sun.java2d.Disposer.run(Disposer.java:148) at java.lang.Thread.run(Thread.java:745) "Service Thread" #7 daemon prio=9 os_prio=0 tid=0x00007fd46400c000 nid=0x1153 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE "C1 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x0000000001934800 nid=0x1152 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE "C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x0000000001931800 nid=0x1151 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x0000000001930000 nid=0x1150 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE "Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00000000018f7800 nid=0x114f in Object.wait() [0x00007fd468db9000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000000f5906f58> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143) - locked <0x00000000f5906f58> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:164) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:209) "Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00000000018f0000 nid=0x114e in Object.wait() [0x00007fd468eba000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000000f5906998> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:502) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:157) - locked <0x00000000f5906998> (a java.lang.ref.Reference$Lock) "VM Thread" os_prio=0 tid=0x00000000018ea800 nid=0x114d runnable "GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000001896000 nid=0x114b runnable "GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000001898000 nid=0x114c runnable "VM Periodic Task Thread" os_prio=0 tid=0x000000000198d800 nid=0x1154 waiting on condition JNI global references: 389 Heap PSYoungGen total 9728K, used 4357K [0x00000000f5900000, 0x00000000f6380000, 0x0000000100000000) eden space 8704K, 50% used [0x00000000f5900000,0x00000000f5d415a0,0x00000000f6180000) from space 1024K, 0% used [0x00000000f6280000,0x00000000f6280000,0x00000000f6380000) to space 1024K, 0% used [0x00000000f6180000,0x00000000f6180000,0x00000000f6280000) ParOldGen total 22016K, used 0K [0x00000000e0a00000, 0x00000000e1f80000, 0x00000000f5900000) object space 22016K, 0% used [0x00000000e0a00000,0x00000000e0a00000,0x00000000e1f80000) Metaspace used 8578K, capacity 8728K, committed 8832K, reserved 1056768K class space used 980K, capacity 1058K, committed 1152K, reserved 1048576K