1

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.

2 Answers2

5

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.
user207421
  • 990
  • 5
  • 16
  • 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. – user207421 Jul 26 '12 at 02: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 04:47
  • 1
    @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. – user207421 Jul 26 '12 at 07:01
1

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.

Soham Chakraborty
  • 3,534
  • 16
  • 24