Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #32025
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: javax.swing.Timer blocking program termination |
| Date | 2015-07-14 21:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <mo4088$9ph$1@dont-email.me> (permalink) |
| References | (6 earlier) <mo35mi$366$1@dont-email.me> <c284d5a9-951b-424d-88ed-e738dc94edab@googlegroups.com> <mo3810$c12$1@dont-email.me> <mo3kpq$oua$1@dont-email.me> <mo3p67$i12$1@dont-email.me> |
On Tue, 14 Jul 2015 15:51:55 -0400, Eric Sosman wrote:
> On my system (Java 1.8.0_45-b14, Windows 7 64-bit), I observe:
>
> - With a repeating Timer and a delay > 1000 ms, the JVM exits
> 1-2 seconds after the frame closes.
>
> - With a repeating Timer and a delay == 1000 ms, the JVM exits
> 10-25 seconds after the frame closes.
>
> - With a repeating Timer and a delay < 1000 ms, the JVM keeps on
> running after the frame closes, until I lose patience (> 1 min)
> and kill it manually.
>
> - With a *non*-repeating timer, the JVM exits 1-2 seconds after
> the frame closes.
>
> Here's a possible explanation, entirely uncontaminated by actual
> facts: Suppose there's a bit of Java somewhere that monitors the EDT's
> health by polling at about 1 Hz. It asks "Hey, EDT, are you doing
> anything important?" As long as the JFrame is open, the EDT replies
> "Yeah, I've got windows open." The monitor says "Okey-doke" and goes
> about its other business.
>
> After the frame closes, the EDT's reply changes to "There's nothing
> open, but events are still coming along and I'm processing them." The
> monitor says "Ho-kay, you're still doing work" and dozes off again.
>
> But with a > 1000 ms delay, the EDT replies to the next query with
> "No windows, and no events since you last asked." The monitor then says
> "Okay, time to call it a day" and tells the EDT to pack it in. The EDT
> stops, the JVM sees there are no non-daemons running, and shutdown
> commences. With a delay of exactly 1000 ms there's a bit of a race
> between the monitor and the Timer, and several query-response cycles may
> pass before it Just So Happens that two queries bracket zero Timer
> events, hence the long and variable post-close shutdown time in this
> case. And with a delay < 1000 ms, the Timer *always* fires at least
> once between each pair of the monitor's queries, so the EDT *always*
> reports that it's still doing work. And with a non-repeating Timer the
> EDT reports right away that there's nothing afoot.
>
> That sort of mechanism would account for what we've seen so far --
> but "would account for" doesn't imply "is True." The ancients explained
> that invisible gods and demons moved the planets by blowing on them, but
> nowadays such notions aren't widely accepted (outside of Washington DC).
>
> Still not a confirmation, but highly suggestive: I added
>
> addWindowListener(new WindowAdapter() {
> @Override public void windowClosed(WindowEvent evt) {
> timer.stop();
> }
> });
>
> in the constructor, and found that the JVM *always* exited promptly
> after the frame closed, no matter the Timer's delay or repeatability. It
> really, really looks like the endless train of Timer events is what's
> keeping the EDT alive.
>
That looks reasonable to me. Better than my supposition, certainly: I was
speculating that, because there are two threads running you could get out
of order execution between stuff passed to the EDT to initialise and
stuff run directly by the 'main' (implied) thread. And, of course, I
forgot that the timer is running on the EDT.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-13 16:03 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 20:27 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-13 17:46 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 21:35 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 22:13 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-13 22:27 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 06:31 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:15 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:22 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 07:39 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 10:53 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 10:16 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 13:25 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-14 10:45 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 14:16 -0400
Re: javax.swing.Timer blocking program termination Gene Wirchenko <genew@telus.net> - 2015-07-14 12:56 -0700
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 16:14 -0400
Re: javax.swing.Timer blocking program termination e.d.programmer@gmail.com - 2015-07-15 05:11 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 08:33 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-15 18:46 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 21:18 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 22:13 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 10:55 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 08:17 -0700
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 11:42 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-14 18:35 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 15:17 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 15:36 -0400
Re: javax.swing.Timer blocking program termination Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-07-14 15:51 -0400
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-14 21:51 +0000
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 15:08 -0700
Re: javax.swing.Timer blocking program termination Martin Gregorie <martin@address-in-sig.invalid> - 2015-07-15 01:16 +0000
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 16:09 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 18:32 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 18:34 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 20:31 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-14 08:16 -0700
Re: javax.swing.Timer blocking program termination Joerg Meier <joergmmeier@arcor.de> - 2015-07-14 08:32 +0200
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-14 22:18 -0400
Re: javax.swing.Timer blocking program termination Jeff Higgins <jeff@invalid.invalid> - 2015-07-15 08:26 -0400
Re: javax.swing.Timer blocking program termination Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2015-07-15 11:05 -0700
csiph-web