My JVM is closed as soon as I close my Applet

  • Follow


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

0
Reply Matrixinline 9/1/2010 11:23:58 AM

On 09/01/2010 07:23 AM, Matrixinline wrote:
> 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,

System.exit by definition closes out the JVM (to be more precise, it 
terminates the Java process). If you don't want to close the JVM, then 
don't call System.exit...

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth
0
Reply Joshua 9/1/2010 11:30:34 AM


On 9/1/2010 7: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,

     I think this will only happen if the exiting applet is trusted,
which usually means you've signed it and the user has told the
browser to accept your certificate.  Un-sign the applet or tell the
browser to stop trusting the certificate, and I think the problem
will go away.  (Test it to be sure, though: I'm not an expert on
trusted applets.)

     If your applet needs privileged access to the system, that is,
if your applet must be trusted, then you must write it so that it
behaves in a trustworthy way.

> 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)

     Hmmm: Haven't tried it, nor even done more than skimmed the
Javadoc, but can you install your own SecurityManager around your
own applet, subsidiary to the browser's own SecurityManager?  If so,
you could intercept the System.exit() and deny it permission to run.
(And if my first suggestion is tentative, this is *really* tentative!)

-- 
Eric Sosman
esosman@ieee-dot-org.invalid
0
Reply Eric 9/1/2010 12:06:12 PM

On Wed, 1 Sep 2010 04:23:58 -0700 (PDT), Matrixinline
<anup.kataria@gmail.com> wrote, quoted or indirectly quoted someone
who said :

>I have two applets on a page. One applet starts a frame. When I close
>this frame (JFrame) I call System.exit).

 Applets are not ever supposed to call System.exit unless something
incredibly fatal has happened.  It is up to the browser to call stop
and destroy.

-- 
Roedy Green Canadian Mind Products
http://mindprod.com

You encapsulate not just to save typing, but more importantly, to make it easy and safe to change the code later, since you then need change the logic in only one place. Without it, you might fail to change the logic in all the places it occurs.
0
Reply Roedy 9/1/2010 4:37:38 PM

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/>
0
Reply Daniel 9/1/2010 5:44:45 PM

4 Replies
318 Views

(page loaded in 0.045 seconds)


Reply: