Re: My JVM is closed as soon as I close my Applet
On 9/1/2010 4:23 AM, Matrixinline wrote:
Hi All,
I have two applets on a page. One applet starts a frame. When I close
this frame (JFrame) I call System.exit). Now this cause my JVM to
exit. It causes my other applet also gets destroyed,
Can you please let me know the solution for this. (I do not wish to
remote system.exit call, this will cause me major re-work)
Can we not load two JVMs for two applets in a browser ?
Thanks
Anup
Most applications should *never* call System.exit(). They should inform
all there non-daemon worker threads to terminate, and should dispose any
active windows (calling frame.dispose()).
For several reasons:
One, the problem you describe above.
Two, System.exit() may through a SecurityException, and you gain nothing.
Three, System.exit is a hard exit. Some external resources may not
get properly shut down.
Four, it makes programs hard to extend. What you used to consider
"the end of the programs life" may now just be the end of the first phase.
Usually, I use
JFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE).
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>