users@grizzly.java.net

concept for handling out of memory

From: <gonfidentschal_at_gmail.com>
Date: Fri, 20 Apr 2012 01:19:25 +0000 (GMT)

if there is documentation for this, could someone point me to it? i
could not find it.

use case:
embedded grizzly for web services. testing application under load and
with limited memory to provoke OutOfMemoryError.

what works fine:
if just one request/thread requires a lot of memory and then throws the
OutOfMemoryError the vm may recover and continue as if nothing
happened.
i can log the error, and a sysadmin may look at it later on and assign
more memory if he wishes to, or pass the case on to a developer to
lower memory requirements per thread .
there is no immediate action required since other requests will work
fine.

what doesn't work:
when the situation is caused by the main application and not just one
thread, the vm will try to handle it and keep running. the performance
will be totally inacceptable and many requests will either time out or
get the same OutOfMemoryError.
this needs immediate action by the sysadmin to restart the application.
it might then run fine for a while or long time until memory fills up
again. he may also assign more ram to the vm.
this is my situation, and i would like to make the application exit.
the exit will cause the error to be logged, the sysadmin to be
informed, and the application to be automatically restarted (using a
wrapper around my application). the downtime will be short, and the
sysadmin has some time to analyze the situation and assign more memory
for next time.

how do i achieve this?
is there anything built in that can be enabled for acting based on
OutOfMemoryError in a single thread? a strategy to implement, for
example exit on first occurrence, or on 3rd within a certain amount of
time? or should i listen to it with
Thread.setUncaughtExceptionHandler()?