Re: Out-of-Memory Handling in Long-Running / Server Applications

Endre Stølsvik <[email protected]> Sun, 13 Apr 2008 22:36:01 +0200
Newsgroups gmane.comp.windows.devel.java.advanced
Message-ID <[email protected]>
Randall R Schulz wrote:
> On Sunday 13 April 2008 13:08, Endre Stølsvik wrote:
>> Randall R Schulz wrote:
>>> Hi,
>>>
>>> When memory is exhausted in the inner loop of the program (the only
>>> place it's going to happen), I catch the OutOfMemoryError, release
>>> the storage, trigger a GC (forcing it would seem desirable, but I'm
>>> not sure how to do that) and report the failure back up the call
>>> chain.
>> Interesting.
>>
>> ...
>>
>> However, I'm a bit sceptical to this, since I believe I've read that
>> after a OOM, you'd better throw away the entire JVM, since it'll be
>> unstable and generally not feeling all that good - and you might get
>> any kind of problems later on.
>
> One of the biggest weaknesses of the sorts of techniques that you and I
> are using is that the OOM may be delivered to another thread (instead
> of or in addition to being delivered to your own).

Is this really so? Because at least in my situation, it is one specific
thread that tries to allocate this huge block of memory. I gathered that
it is this thread that will get the OOM - and since it doesn't really
allocate it afterall (it failed with the OOM!), there is enough memory
available for everything else right afterward.

Is it really possible that _while_ trying to allocate this e.g. 64 MB
int array, some other thread gets a OOM? I would assume that the 64 MB
was tried allocated in one chunk, and when some 'if' inside the
allocation method realized that this won't happen, it'll not allocate
the memory afterall, and throw an OOM. I envisioned that this particular
operation was "atomic" - either there is enough memory, and the piece is
allocated, or there isn't, and the piece isn't allocated.

>
> The technique presented in the article referred to by Burt B. looks good
> to me, and I'm in the process of implementing it in my application now.
>
>     <http://www.javaspecialists.eu/archive/Issue092.html>

This won't do it for me, as it _should_ be enough memory, and often also
looks like there is enough memory, but I get the OOM anyway. After a GC
or five, the JVM seems to agrees with me..!

Endre.

===================================
This list is hosted by DevelopMentor®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com