Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.exit(0) in Swing

 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd check to see if the propertyChangeListener was getting called every time... add some logging at the start of the propertyChange() method.
 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic