• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hw to shut down swing without using System.exit()

 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to run a Swing application in an environment in which I cannot call System.exit(), because, among other things, the environment must do some cleanup after the program relinquishes control. Any ideas on how to shut it down? I currently end up with the following non-daemon threads still running (as seen when testing under the VAJ debugger):
AWT-EventQueue
AWT-Windows
Screen-Updater
SunToolkit.PostEventQueue
I think I've already cleaned up all the threads I explicitly started, and disposed of all Windows, so these seem to be the residue from Swing.
Thinking about it a bit more, I'm not sure I should stop these threads. It may be that the JVM on which I'm running will need them for other purposes, or clean up at an appropriate time, perhaps by exiting. But I'm still interested in your answer.
[This message has been edited by John Dale (edited October 12, 2001).]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that if you call dispose() on the frame references, the window will close and all system resources allocated to the frame are released( including threads )...

-Nate
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pretty sure I'm calling dispose() on each top-level container (JFrame and JDialog). The windows disappear from the screen, but those four threads, plus various daemons, hang around.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The garbage collector that is build into the JVM takes care of all that for you, so I don't believe there is a way to dump it until you exit the System. Unless you could make some calls directly to the JVM but you would have to use another language to do that.
One of those downsides to a middleman(JVM) controlling the execution of your program.

------------------
Happy Coding,
Gregg Bolinger
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... when you run your screens from the command line, does the program let you return to the system, or does the system hang when you try to exit?

-Nate
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Running from the command line, the GUI disappears, but the java command doesn't terminate, because there are still non-daemon threads.
Note that I've removed all the System.exit() calls, so the non-daemon Swing-related threads keep the VM alive. The GUI goes away because of dispose() calls.
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that there is a better way for me to do this than to run as a Swing application in this environment. But I learned some from trying. Thanks for looking at this with me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic