Java OutOfMemoryError


On a machine with memory issues my Java app kept crashing due to an OutOfMemoryError:
Exception in thread “Thread-1” java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:657)

I started logging thread counts and memory usages and neither one was increasing/leaking. I tried to catch the ‘Exception’ as it was claiming but the app would still fail.

Finally I read the javadoc on the java.lang.OutOfMemoryError and discovered that the error inherits from Error and Throwable rather than Exception so I was not able to catch it. Catching the Throwable allowed me to keep my app going.

http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/OutOfMemoryError.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s