aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Hw to shut down swing without using System.exit() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hw to shut down swing without using System.exit()" Watch "Hw to shut down swing without using System.exit()" New topic
Author

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

John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
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

Joined: Oct 18, 2000
Posts: 4121

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

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


GenRocket - Experts at Building Test Data
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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

Joined: Feb 22, 2001
Posts: 399
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

Joined: Feb 22, 2001
Posts: 399
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hw to shut down swing without using System.exit()