Hi everyone!
I'm trying to get this thing with using different ClassLoaders to work with no success and I'm getting kind of desperate. What I'm trying to do is to launch 2 different instances of a 3rd party program that was created with several static attributes and therefore can't just be instantiated twice in my code. I've been advised to use different ClassLoaders to load the .jar file, though I don't really know how to do this. Could I maybe get some pointers on where I could start?
I also need to pass an object of my own program to this program instance and I also have no idea of how I could do this...
Thanks in advance for the help, Andre
PS: This whole discussion started in the java forums, so there's a more detailed description of what I need to do and why I need to do this. The advice I'm referring to in this post was from malcommmc:
Another approach might be to run the whole system in one JVM, but create a new classloader for each instance of the 3rd party code and make sure that the classes containing the offending statics are only loadable by these new class loaders. Under these conditions the JVM can support multiple copies of the same class, providing the FQN is unique within a class loader.
In this case run each instance as a separate Thread, and set the thread's context class loader to point to the relevant class loader.
Presumably the object you are proposing to pass is specified with some interface or abstract class known to the 3rd party app. You need that interface to be known to the system class loader, i.e. on the class path, but the principal classes of the 3rd party app must not be on the classpath, but be accessed as a jar referenced by a URLClassLoader.