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

System.exit(0) in Swing

ram shyam
Ranch Hand

Joined: May 04, 2007
Posts: 77
Hi,

In my Swing application, as soon as I start the main() method, a dialog containing Username and Password fields with OK and Cancel buttons gets popped-up. I have a propertyChangeListener which gets notified when Ok or cancel is pressed and when Cancel is pressed, System.exit(0) is called to exit the JVM.

So, there are two threads running -
One - the main thread which invokes the dialog pop-up
Second - the propertychangelistener which calls the System.exit(0) on pressing Cancel button.

So, at times, after pressing cancel button, the application does not exit but invokes the previously running thread (main thread). But this does not happen always.

Could you please let me know why the application does not terminate completely and how to resolve this?

Thanks in advance!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I'd check to see if the propertyChangeListener was getting called every time... add some logging at the start of the propertyChange() method.


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

Joined: May 04, 2007
Posts: 77
hi,

But at any cause, after calling System.exit(0), how can the main thread continue to run?
Is this possible?
Please clarify.

Thanks in advance!!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It can't (without some special cases, like having a shutdown hook that never exits) - that's why I suggested looking into whether the PropertyChangeListener was actually getting called.
 
 
subject: System.exit(0) in Swing