It is typical in J2EE containers to run multiple applications in the same JVM. Each application is deployed in an EAR and has its own classloader. Controlling the memory size for the entire JVM is trivial. However, we want to put a limit on the max memory that can be used by each application in the same JVM. E.g. JVM max heap is 512 MEG and there are three applications (A, B, and C) running in the JVM. We want to limit the size of application A to 256 MEG and applcaiton B and C to 128 MEG each.

We want to do this so that even if app A is an out of control application (memory leak etc.), it can't take more than the allocated quota and crash the JVM along with other apps.

Running apps in seperate JVM is not desired due to the container (J2EE server) over head. Basically we are looking for the best of both world, i.e. more control and roburstness of out-of-memory-process with the advantage of performance and smaller footprint of in-memory process.

Wondering if someone has address this problem by some how limiting the memory size that can be used by a classloader to for loading objects in memory.