Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

How to tell system threshold for Java Heap OutOfMemoryError?

Thread view: 
BogusException - 10 Aug 2006 04:32 GMT
Situation: Program using lots of threads, communicating between them
with LinkedBlockingQueues.
Problem: Unbounded queue throws OutOfMemoryError. How to
anticipate/measure system capcity, and ultimately adjust queue sizes as
conditons on the server changes (to avoid throwing the excepton at
all).

Filling a Queue (LinkedBlockingQueue) with elements, I run into a
number of total elements in the queue where I throw a Heap error:
OutOfMemoryError. Once the queue (unbounded) reaches this heap limit,
it throws Java Heap OutOfMemoryError. The heap is used to track all
objects in memory, right? I thought RAM was used to store objects, and
heap was used to track each object in all threads.

This might not be a queue error at all, but merely a "too many objects
in all threads to keep track of" problem. Filling the queue with too
many elements might just trigger the condition.

Is there a way to anticipate the queue's capacity for objects, and thus
stop offer()-ing and direct element candidates elsewhere until the
queue's capacity increases? If the known system capacity for elements
in the queue were known, I could manage the queue capacity threshold
for each queue. The idea might be to anticipate the system's capacity
at runtime and configure a limit to the queue, instead of leaving it
unbounded.

In addition, I wonder if using a ConcurrentLinkedQueue might be more
robust than the LinkedBlockingQueue I'm using now. I can't seem to find
any performance comparisons or benchmarks.

TIA!

BogusException
Vincent van Beveren - 10 Aug 2006 15:31 GMT
An OutOfMemoryError is thrown when the maximum amount of memory assigned
to Java is used. It has nothing to do with the number of objects in a
particular thread or the number objects referenced, only the amount of
memory the total of all the objects use in the VM. You can set the
memory threshold with -Xmx and -Xms (execute 'java -X' for more
information).

To get the total amount of memory the VM can assign you can use the
following (somewhat complecated) code:

Runtime r = Runtime.getRuntime();
long usedMemory = r.totalMemory() - r.freeMemory();
long assignableMemory = r.maxMemory() - usedMemory;

The point is that the JVM increases its memory in steps... total memory
gives the total of the current step, but maxMemory gives the total
memory the JVM will try to use. This the above rather complecated
statement. You can run a thread that checks the assignable memory every
so-many-seconds. There are somewhat more advanced features in the
java.lang.management package which you can use if you want more control.
Check it out.

Vincent

> Situation: Program using lots of threads, communicating between them
> with LinkedBlockingQueues.
[quoted text clipped - 29 lines]
>
> BogusException


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.