My program is entirely JavaScript, and I'm using the Rhino shell to
execute it, so I don't have the ability to add Java try/catches for
VirtualMachineErrors without modifying the shell. I could do that, but
I'd rather not. Would it be something worth adding to the official
Rhino shell?
But regardless of that, Java doesn't always seem to hang like this.
For example, if you just do something like:
blah = [];
while(1) blah.push("blahblahblah");
and execute it in the Rhino shell java will quickly throw the OOME
*and exit*.
But in my program it doesn't exit, it throws OOME and hangs.
Thanks,
Tom
On Jan 9, 8:43 am, Attila Szegedi <[email protected]> wrote:
> It's (unfortunately?) normal that a JVM doesn't exit on OOME. If you
> have a top-level processing loop, you can do a:
>
> try
> {
> ...}
>
> catch(VirtualMachineError e)
> {
> System.exit(123);
>
> }
>
> or similar. I tend to have such catches in my production stuff, since
> if you get a VirtualMachineError (of which OOME is one subclass), then
> all bets are off with regard to correct future execution of that VM
> instance -- you can't count even on finally blocks completing, streams
> being flushed (potentially leading to incomplete file writes), etc.,
> so indeed the best course of action is exiting as quickly as possible
> and making sure monitoring staff spots it immediately.
>
> One possible exception you might want to make is for
> StackOverflowError -- it too is a VirtualMachineError, but is normally
> localized in effect to a single thread. However, it too can cause VM
> guarantees to fail; a finally block executing after a SOE might get
> another SOE itself if the stack is still very deep while in the
> finally block, so I usually don't bother making an exception for it
> and my code does a System.exit() whenever it spots any
> VirtualMachineError.
>
> Attila.
>
> --
> home:http://www.szegedi.org
> twitter:http://twitter.com/szegedi
> weblog:http://constc.blogspot.com
>
> On 2009.01.09., at 16:10, Tom Robinson wrote:
>
>
>
> > I have a fairly complex JavaScript app I run using the Rhino shell.
> > Occasionally it runs out of memory and throws the OutOfMemoryError
> > exception. I expect the java process to exit at that point, but it
> > doesn't. No code seems to be executed after that point, but the
> > process doesn't exit.
>
> > This is rather annoying because then I can't check to see if the
> > process has crashed and automatically restart it.
>
> > I'm having a hard time creating a simple reduction. Has anyone
> > experienced anything like this in Rhino, or Java in general?
>
> > Thanks.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino