The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
July 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Need help running multiple apps on same JRE

Posted by Matt Senecal on July 30, 2001 at 1:49 PM

I've written an application that serves as a floating desktop "button bar" (call it MyApp). The requirements for it were that:
1. All the java applications lauched from it had to all run on the same JRE
2. MyApp had to be completely ignorant of the applications it would be launching. That is, when MyApp runs, it reads a prefs file to get information (location, class names, etc.) on the classes it will have to load.

An application's main class is loaded like so:


URL[] url = {new URL("file:jar:/C:/Files/Test/blah.jar!/")}; //Normally, this is read from the prefs fileURLClassLoader ucl = new URLClassLoader(url);Class theClass = ucl.loadClass("Blah"); //Ditto.


The application is launched like this:


Method method = theClass.getMethod("main", bd.getClassArray());Object obj = method.invoke(null, bd.getObjectArray());


The application is lauched by MyApp (and MyApp retains no reference to it at all). Technically, the launched application is running as a seperate process on the JRE (a thread launched by MyApp), but the effect is the same. So far, so good.

PROBLEM: I had to implement a custom SecurityManager that prevented a quitting application (using System.exit()) from killing the JRE (and hence all the other Java apps). Side effect: the application stops running, but the memory it used isn't reclaimed. MyApp has no refence to the application that
was launched, and can't explicitly kill it. Hence MyApp is a slow, and potentially very large, memory leak. Not good.

Does anyone know of another way to do this? A method that would keep a reference to the launched processes so they could be explicitly terminated? Is there a way for my custom SecurityManager to get a handle on the process that initiated the System.exit()? Any help would be appreciated.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us