Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a Tomcat server that serves many webapps, each with many servlets. Sometimes, a single servlet of a single webapp runs out of memory, and then the entire Tomcat crashes with a Java "Out of Memory" error, and I have to restart it.

Is there a way to isolate the servlet, so that when it runs of of memory, it does not crash all other apps?

I currently run Tomcat 7 on Windows, but I may soon move to Linux, so answers for both platforms are welcome.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

No there isn't. You have to either:

  1. Stop it consuming so much memory
  2. Give Tomcat more memory, or
  3. Install it in its own instance of Tomcat so that when it crashes it doesn't take your other webapps with it.
share|improve this answer
    
Too bad. Is there maybe another servlet server that can do this? –  Erel Segal Halevi Jul 23 '12 at 12:21
    
@ErelSegalHalevi I don't see how there could be, but I'm open to correction. The whole idea is that everything shares the same JVM. You might be surprised how easy and painless it is to set up another one, or two ... Might get you started along the path to clustering, like it did for me. –  EJP Jul 26 '12 at 2:50
    
OK, and if I start a new instance of Tomcat, do I have to give it a different port? (that means that the web address of my webapp will change). –  Erel Segal Halevi Jul 26 '12 at 4:47
    
@ErelSegalHalevi At that point you would front-end with an Apache HTTPD on ports 80 and 443, talking probably only AJP to the Tomcats on their AJP Connector ports, via mod_proxy_ajp. That gives you several other benefits like being able to impose stronger access control on the Tomcat Managers to keep out the bandits, who do exist and are very malevolent, and also much finer-grained control over SSL as well. The Tomcat HTTP Connectors can be completely removed. And they don't even need different ports: just use address="127.0.0.[1234...]" respectively, as many as you need. –  EJP Jul 26 '12 at 7:01
    
Great material for study, thanks... –  Erel Segal Halevi Jul 27 '12 at 5:57
add comment

In Linux, I have seen that OOM messages 'usually', I again say 'usually' point to a more bigger memory size. That means either increase the RAM or get a bigger swap space. The first option is preferred.

Architecture of the system also matters but what I have seen it is usually a problem of sizing the work load. Which means run less applications or generate less load or get bigger memory.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.