You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andy Cooke <ce...@cee.hw.ac.uk> on 2003/08/06 18:02:42 UTC
OutOfMemoryError
Hi there,
We have a tomcat application that uses servlets to hold state on behalf
of API users - kind of like a database.
If API users store too much info, then eventually an OutOfMemoryError
results, and the servlet container crashes:
> 06-Aug-2003 16:34:45 org.apache.tomcat.util.log.CommonLogHandler log
> SEVERE: Caught exception executing org.apache.tomcat.util.net.TcpWorkerThread@163956, terminating thread
> java.lang.OutOfMemoryError
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 about
to run out?
I thought at first we could simply monitor Runtime.getTotalMemory(),
etc. e.g. refuse request if:
(totalMemory - freeMemory) > some % of the maxMemory
but it seems the situation is more complex. These are the numbers just
before the crash:
free Memory = 172544, totalMemory = 6.6650112E7, maxMemory =
1.34217728E8
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 of
memory that it should have been allocated?
thanks for any suggestions,
Andy Cooke
--
Heriot-Watt University