tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <>
Subject RE: OutOfMemoryError
Date Wed, 06 Aug 2003 16:51:53 GMT


>Does any one know of a neat way of monitoring memory usage, so that our
>servlet can decide to refuse a request if it senses that memory is
>to run out?

You have the two calls in the Runtime class (totalMemory() and
freeMemory()), and that's pretty much it.  This of course reflects only
the heap.  So you can have a background thread that checks freeMemory()
every so often and if the free percentage falls below a certain
configured threshold, sets some global flag variable that servlets (or
better yet a simple filter) consults when deciding whether to allow
servlet requests.

>free Memory = 172544, totalMemory = 6.6650112E7, maxMemory =

How were the above obtained?

>and I don't understand why the JVM didn't try to grab more memory when
>it could - is it because one of tomcat's threads unexpectedly ran out
>memory that it should have been allocated?

The JVM is constricted by how you configure it, e.g. the -Xmx parameter.
If not specified, the JVM will allocate up to 64MB to the heap.

>thanks for any suggestions,

This is a fragile situation with or without the above solution.
Benchmark your system to know how many max concurrent requests you can
support given your hardware, and make sure your customers/users know
this number.

You may also want to consider a script to monitor your log for
OutOfMemoryError messages and restart tomcat or notify admins in this

Yoav Shapira

This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.

View raw message