0

I've seen a lot of Swing app setups, and I always wonder what exactly makes them blocking until the close button is pressed, like in the official:

Oracle Swing HelloWorld

I mean, if SwingUtilities.invokeLater is async, where is the main thread blocking?

Jon Heller
  • 34,999
  • 6
  • 74
  • 132
Whimusical
  • 6,401
  • 11
  • 62
  • 105
  • 4
    The main thread is not blocking. Using swing starts another thread: the event dispatch thread. The JVM only stops when *all* non-daemon threads have stopped. Not just the main thread. – JB Nizet Jan 12 '16 at 17:34
  • Nice, now I understand what that setDaemon thing did mean in Thread :) – Whimusical Jan 12 '16 at 17:37
  • Anyway, where is this daemon thread exactly called? – Whimusical Jan 12 '16 at 17:37
  • 1
    It is not a daemon thread. Otherwise the JVM would stop. AFAIK, it is started as soon as invokeLater is called, or a top-level component is made visible. But I might be wrong here. – JB Nizet Jan 12 '16 at 17:42
  • 1
    I suggest checking out [this answer](http://stackoverflow.com/questions/26317766/when-is-the-swing-ui-thread-created/26319685#26319685) to find out how/when the EDT is created – Vince Jan 12 '16 at 18:13

1 Answers1

0

The main thread isn't blocked or sleeping at all. It has exited.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Could you elaborate bit further please, in the vein as some comments (3 or 4 lines), so I can accept it? – Whimusical Jan 12 '16 at 20:39
  • I don't see how, or why. What part of 'it has exiited' don't you understand? – user207421 Jan 13 '16 at 06:17
  • I don't know, JB Nizet comments are far more detaled explanation, I felt sorry to accept an answer while those comments are more valuable for the community – Whimusical Jan 19 '16 at 17:42