views:

407

answers:

4

I'm curious if there are any Java abstractions that are similar to .Net's AppDomain.

In particular, I'm curious because I've found that with our Coldfusion/J2EE server we need to restart it every few days due to a slow memory leak that we haven't been able to easily track down yet. This can wreck our long-running processes and we'd really like a way to slowly just push people to new JVMs as they age past a certain time period/memory threshold.

From my limited .Net experience I'm pretty sure that this is one situation that IIS and AppDomains are able to manage fairly seamlessly by recycling AppDomains that come under memory pressure. Please let me know if I'm way off on AppDomains helping in this scenario.

Any suggestions?

A: 

Recycling of individual JVMs on the basis of time or specific criteria such as growing memory consumption and memory use threholds is a capability of the advanced versions of the App Server I work with, WebSphere. If your App Server does not have that capability, then crafting some shell scripts to give something like that function should be doable.

This works quite nicely assuming:

a). Requests from users are sprayed around the a larger set of JVMs. b). That all requests are stateless or there is some state replication capability. Replication is a capability of WebSphere and WebLogic, I'd guess that other app servers have the capability too.

In such environments there's no need to "slowly" move people to other servers. We just need to know that we can safely stop any one serve/JVM and that these sessions will pick up on another instance.

djna
Thanks for your comment. Unfortunately my web app is currently both not stateless and replication is not possible because session is not serializable. Perhaps I'd be best served by making everything in there serializable.
Bob Albright
A: 

What version of CF are you using? How many instances are you running on a single physical server? Why can't the session be serialized? Are you using objects (CFCs) in session on CF 6 or 7? If so, there are ways around that that don't include being stateless.

iKnowKungFoo
+1  A: 

Unfortunately, no.

The analogous concept in the Java world is the Isolate, that appeared first in the JSR 121. This was an API for a future JVM feature that would allow safe separation and communication between different applications running in the same JVM. After the JSR was published (around 2004) one research team in Sun worked in the Barcelona project. This project tried to implement the Isolation API in Sun's HotSpot 1.5 VM. After two years, they released a prototype for SPARC/Solaris. Windows/Linux versions were never released due to stability problems.

Recently, SUN has introduced a limited version of the Isolation API to J2ME, focusing of offering "multiple processes" in environments that didn't actively offer them. Recently, we also asked Sun for their status in implementing the Isolate API to standard JVMs and their response was that they plan to release a JVM with limited support. They plan to offer the ability to load/unload Isolates but without the ability to communicate between them.

Also, there has been an old reserach efford to build an Isolates-compatible JVM version, called JanosVM (java 1.1) but I doubt that it can be of any use today.

Hope this helps...

Papajohn
Thanks! That was really interesting and informative!
Bob Albright
+1  A: 

I think the accepted answer here is a little misleading. Simply saying "no, you can't" is not the whole story. The question is focused on unloading Java classes in a server process to remove leaky code from the JVM process without a process restart. The OP is not asking for the process-like memory isolation feature that an AppDomain gives, but the ability to unload classes in a running JVM. I say process-like, since under the hood an AppDomain is not a process, but enjoys some of the isolation aspects that a first-class process is afforded by the operating system. The isolate JSR mentioned is referring to this 'process-like' isolation. Unloading java ClassLoaders and thus classes, without cycling the OS process hosting the JVM is possible. A couple of methods are mentioned here: SO 148681. It is not trivial, or elegant to do this in Java, but it is possible.

Todd Stout
Right you are. Thanks for the response.
Bob Albright