[concurrency-interest] Exception handling & Executors

Joe Bowbeer joe.bowbeer at gmail.com
Tue Oct 25 15:55:12 EDT 2005


On 10/25/05, Jan Nielsen <jnielsen at sungardsct.com> wrote:
>
> With respect to your comment below about not being able to do anything
> with an out-of-memory condition, could you not reliably release, for
> example, cached data in an OutOfMemoryError handler:
>

In my experience, recovery from OOME is dicey at best and therefore
the only robust approach is to design and implement the app in such as
way that OOME never happens.

(Note: real-time Java tells a different story.)

I haven't investigated carefully why OOME recovery is dicey, but since
nothing is supposed to catch it I assume that once it is thrown the
system is in an unrecoverable state: no cleanup has been performed
along the way, connections and streams are broken, third-party
libraries are left in some indeterminate state, etc.

If your app could control where the OOME occurs then it would have a
better chance to catch it and recover -- by releasing buffers, for
example.  But I don't have a lot of faith that this can be done
reliably (or efficiently).


On 10/25/05, Jan Nielsen <jnielsen at sungardsct.com> wrote:
> Joe,
>
> With respect to your comment below about not being able to do anything
> with an out-of-memory condition, could you not reliably release, for
> example, cached data in an OutOfMemoryError handler:
>
>   Map m = new HashMap();
>   Object o = new PreAllocatedMemoryInBytes( 16 );
>   try
>   {
>     // blah, blah, blah...allocating all the memory to 'm' values...
>   }
>   catch( OutOfMemoryError e )
>   {
>       o = null;
>       m.clear();
>       // only log after we have enough memory
>       e.printStackTrace();
>   }
>
> The m.clear() method may require some allocation to work, so it would be
> susceptible to failure without having that much available memory,
> specifically:
>
>     public void clear() {
>         modCount++;
>         Entry[] tab = table;
>         for (int i = 0; i < tab.length; i++)
>             tab[i] = null;
>         size = 0;
>     }
>
> In the single-threaded case, pre-allocating sufficient memory to perform
> this operation should address this, should it not?
>
> Thanks,
>
> -Jan
>
> Joe Bowbeer wrote:
> >
> >I don't know how you expect to do anything with an
> >OutOfMemoryException, except perhaps log it.  I don't know of any way
> >to reliably recover from these.
> >



More information about the Concurrency-interest mailing list