|
|
How do I set the memory size of my JVM in automatic mode? (Out of memory exceptions) |
| In your "jserv.properties" file, add a setting like this: wrapper.bin.parameters=-mx64m to set the maximum heap size to 64 megabytes. cmcclanahanATmytownnetDOTcom | |
| From: Godmar Back gback@cs.utah.edu
To: java-apache-users@list.working-dogs.com
Subject: Re: Exceptions / Errors and catching unexpected ones.
Date: Thu, May 6, 1999, 4:44 PM OutOfMemory exceptions are thrown when the JVM runs out of heap space, not stack space. By that time, the JVM will have tried to garbage collect and drop weak refs already. (Which, btw, the suggestion to invoke System.gc() in a catch(OutOfMemory ) clause does not work.) Let me quote the VMSpec: 3.5.3
[...]
The only instance when lack of stack of space causes an out of memory error
is when the native method stack cannot be extended.
For your convenience, I quote the complete VMSpec subsection:3.5.6 Native Method StacksHow do you know that what causes the out of memory error in the case discussed was a failure to allocate more memory for the stack? I would have thought that this would only happen if you set a *very* large stack limit and then entered a buggy recursive function. You may also want to try a VM that does not dynamically expand its stacks, such as Kaffe. If you still get an OutOfMemoryError (as opposed to a StackOverflow) exception, you could be sure that not being able to expand the stack has nothing to do with it the problem --- otherwise, you would have gotten a StackOverflowError. In general, reacting to OutOfMemoryErrors is hard. First, you need a VM that supports it (Kaffe currently doesn't, I don't think the JDK does either.) The JVM has to throw the error at a point in time where there are sufficient resources for the program to proceed to a point where it can drop references (either by terminating threads or by explicitly dropping (zeroing out) references) and then invoke a gc. This is not trivial to implement. - Godmar | |
|
There are several things that one can do about out-of-memory errors. The best thing is to figure out why you are getting them. Jprobe might be useful in this regard. Unfortunately, that is not feasible for me. jserv will run for a month or two unattended before abruptly dying on an out-of-memory error.
I wrote a script that watches my jserv log and restarts the thing if it starts getting servlet errors. This is brutal but effective as far as I can tell. Here is my very nutty script:
The other solution that has been bandied about in the mailing list is to modify memory usage of the jvm. I guess that means modifying jserv.properties so that
wrapper.bin.parameters=-Xms128m -Xmx156m
for Java 2.
Tom Howland | |
| [Append to This Answer] |
| Previous: |
|
| Next: |
|
| ||||||||||