views:

246

answers:

3

I am having two webapplication running inside tomcat. Java Heap space is allocated for Tomcat and it is shared for both appliaction. In that one application consumes more and other is getting OUT_OF_MEMORY.

Is there any way to set memory settings per web application. Say 70% for one webapp and 30% for other from the overall memory allocated to Tomcat.

Regards Ganesh

A: 

No. There is no way for some portion of java code to control the consumption of memory by other portion of code called from first portion of code. In other words, the web container is just a java program which calls some other java class methods found in application.

So the only control one has is JVM arguments. And this arguments are only to hint the JVM where approximately to fail with out of memory error. No, it is not possible.

RocketSurgeon
+2  A: 

The memory is defined per JVM instance, so if you are using one tomcat you cannot do it.

However you can run two tomcat instances - one per web application - and then you will finer control on memory allocation for each webapp.

David Rabinowitz
A: 

This makes no sense. If you want to allocate the desired memory size per webapp yourself, then at least one webapp will at end still crash with OOME. With your idea you would in theory only avoid that the other webapp crashes. It is not true that the one webapp cannot reclaim memory from the other webapp. They both share the same memory and GC. If JVM encounters an OOME risk, then it will run GC anyway and this involves the all webapps.

The real solution to your problem is simply to give it more memory. I would run a profiler anyway to detect memory leaks in the webapps and fix it if any.

BalusC