0

I suspect in my application that an outofmemoryerror is causing a a run() to exit, however because there were no logs, the error wasn't visible.

What should i do in this case?

Oh Chin Boon
  • 23,028
  • 51
  • 143
  • 215
  • If an `Exception` or `Error` is uncaught, it should appear in the output (`System.err`). – Andrew Thompson Oct 17 '11 at 08:45
  • 1
    Usually the JRE will print a stack trace when there is an uncaught exception. What runtime environment are you using where there would be no logs? – Ted Hopp Oct 17 '11 at 08:45
  • possible duplicate of [Will OutOfMemoryError cause a thread to die?](http://stackoverflow.com/questions/7791239/will-outofmemoryerror-cause-a-thread-to-die) – user207421 Oct 17 '11 at 09:02
  • Possible duplicate of [Catching java.lang.OutOfMemoryError?](http://stackoverflow.com/questions/2679330/catching-java-lang-outofmemoryerror) – Raedwald Nov 20 '15 at 09:26

3 Answers3

2

You should run your JVM with this flag: -XX:+HeapDumpOnOutOfMemoryError to see whats happening inside the JVM while the OOM happens. This will write a HPROF file, which you can analyze with a profiler, Eclipse MAT is a good one for this. Use -XX:HeapDumpPath=/tmp to configure the path where to write the HPROF to.

HefferWolf
  • 3,894
  • 1
  • 23
  • 29
1

I do not see a reason as why you can not do that as parent and child threads all are spawned in the same JVM and they share the same heap memory. There are rare requirements to catch OOM errors though as explained here

Saurabh
  • 7,894
  • 2
  • 23
  • 31
1

I don't know about others, but never (IMHO) catch or throws anything that extends Error. The followig statement from the javadoc states:

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.

An Error is printed with System.err and if you want to avoid OutofMemoryException, increase your heapsace instead.

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
  • Just because they should never occur does not mean, that they cannot occur. Threr might still be some special case where you know how to handle things more gracefully than just failing. In case of the poster, there might be the possibility at least to stop the rest of the application without leaving the environment in an inconsistent state. However, one should keep in mind, that stopping an application suffering from an oome might itself lead to another one. – Jonathan Oct 17 '11 at 19:13