: Usually any good piece of java code refrains from capturing Throwable
: so that Errors will bubble up unlike exceptions. Having said that,

Even if some piece of code catches an OutOfMemoryError, the JVM should 
have already called the "-XX:OnOutOfMemoryError" hook - Although from what 
i can tell, the JVM will only call the hook on hte *first* OOM thrown

(you can try the code below to test this behavior in your own JVM) 

: > I'm trying to be notified when the error occurs.  I saw with the jvm I can
: > pass the -XX:OnOutOfMemoryError= flag and pass a script to run. Every time
: > the out of memory issue occurs though my script never runs. Does solr let

...exactly what JVM are you running?  this option is specific to the 
Sun/Oracle JVM.  For example, in the IBM JVM, there is a completley 
different mechanism...

http://stackoverflow.com/questions/3467219/is-there-something-like-xxonerror-or-xxonoutofmemoryerror-in-ibm-jvm


------ Simple OnOutOfMemoryError hook test -----
import static java.lang.System.out;
import java.util.ArrayList;
public final class Test {
  public static void main(String... args) throws Exception {
    ArrayList data = new ArrayList<Object>(1000);
    for (int i=0; i<5; i++) {
      try {
        while (i < 5) {
          data.add(new ArrayList<Integer>(100000));
        }
      } catch (OutOfMemoryError oom) {
        data.clear();
        out.println("caught");
      }
    }
  }
}
------ example of running it -------
hossman@bester:~/tmp$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)
hossman@bester:~/tmp$ java -XX:OnOutOfMemoryError="echo HOOK" -Xmx64M Test 
#
# java.lang.OutOfMemoryError: Java heap space
# -XX:OnOutOfMemoryError="echo HOOK"
#   Executing /bin/sh -c "echo HOOK"...
HOOK
caught
caught
caught
caught
caught
hossman@bester:~/tmp$ 
------------------------------------------



-Hoss

Reply via email to