1

the application I'm responsible for wrote an OutOfMemoryError into one of the logs 5 days before the application stopped to write anything to any of the various application logs. When nothing was writen to the logs anymore the application was truly dead as the users called up that the application is not responding.

I'm now a bit puzzled, because I always thought that the JVM is completely hung after an OutOfMemoryError. The logs show no other error, so I'm assuming the OutOfMemoryError was the problem for the application to stop working.

So the question is whether the JVM can continue to some extend when it has run into an OutOfMemoryError. It's an application based on several OSGi bundles.

Thank you, Oliver

Trying
  • 14,004
  • 9
  • 70
  • 110
OlliP
  • 1,545
  • 11
  • 22

4 Answers4

1

Please look at these Stackoverflow Questions: Can the JVM recover from an OutOfMemoryError without a Restart and Does JVM terminate itself after OutOfMemoryError. They have all the description that you need I feel.

Community
  • 1
  • 1
Trying
  • 14,004
  • 9
  • 70
  • 110
  • Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Joachim Sauer Sep 12 '13 at 08:14
1

An OutOfmemoryError can be caught like any other error and you can continue as if nothing happened. In reality there is a good chance something was left in an inconsistent state and it is best not to continue if you can.

What often happens is this error is not caught and like any uncaught exception or error this results in the thread dying (in this way OOME is not special) When I key thread dies, it usually results in some or all functionality failing as the thread is not restarted.

BTW catch(Throwable) can catch evry kind of error, even ThreadDeath triggered by Thread.slop().

Also BTW, if the error couldn't be caught it wouldn't be printed either. The way it is printed is to catch it first, and then print it.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

After an OutOfMemoryError the JVM might seem to continue working - it certainly doesn't shut down. But experience shows that often it ends up in some strange state where your application seems to be working but produces strange errors or - even worse - wrong results.

So while everything might seem alright I would strongly recommend to restart the JVM after an OutOfMemoryError.

piet.t
  • 11,718
  • 21
  • 43
  • 52
0

once an OutOfMemoryError occurs, you can catch it just like any other error , and try to handle it.

if you handled it nicely (helping the GC to remove heavy objects) , it won't crash your app.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Are you sure about that? From deep down in my memory I think I can remember that the catch block was not executed when I had such an incident long time ago. – OlliP Sep 12 '13 at 08:02
  • you need to specifically add it in the try-catch. it's not a normal thing to catch, but it's possible. not only that , but you can have a global try catch for the entire app , which can help sending crash reports. – android developer Sep 12 '13 at 08:16
  • btw, i was also surprised to see it's possible. but it gives you a lot of power to avoid crashes this way, and even if you didn't succeed, you can send a crash report automatically to yourself to (try to) understand why it happened. – android developer Sep 12 '13 at 08:20