Possible Duplicate:
Catching java.lang.OutOfMemoryError
OutOfMemoryError are:
Thrown when the Java Virtual Machine cannot allocate an object because
it is out of memory, and no more memory could be made available by the
garbage collector
Java says:
An Error is a subclass of Throwable that indicates serious problems
that a reasonable application should not try to catch. Most such
errors are abnormal conditions.
This feels like hearing:
If you are drowning, be reasonable: you should not try to swim upwards
to keep your head above water. Death is typically resulting from
abnormal conditions.
Let’s imagine a scenario where one is running a service. For some reason, another application on the same server is eating a lot of memory, causing an unexpected OOM in your service. Is it such a bad idea to try to reduce this service’s memory consumption in order to remain available to user?
Or is there something more fundamental happening at the JVM level preventing the implementation of such a solution after the OOM has been thrown?
The problem here is that by OOM is an error which should not occur under normal circumstances. By catching it and trying to release memory, you are likely obscuring some sort of leak or unintended behaviour elsewhere.
If you do get OOM, perhaps it’s because you did not configure the JVM to use more memory.