This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I am working on a multiple application launcher. As it runs multiple applications simultaneously it requires that classes of each should be issolated from each other. There is no problem in implementing this. I have completed this using custom classloader. But the new requirement says that if two application refer to some common jar file then they should be shared. The main intension of this is to reduce memory usage. so keeping eye on new requiremtn we have decide to load each jar file using a new class loader. Take an example :
Yes.. Create a classloader to load the common jars, then pass it as the parent to your custom classloaders. When your custom classloader looks up something, it will first go to the parent and load the common jars from the parent classloader.
Hi Geoffrey, The solution you mentioned will work if the child classloader is depends on a single classloader(single parent), but in my case the child classloader is dependant on two or more classloader excpet its own jar file. There is no cyclic dpendancies.
Joined: Aug 17, 2001
This situation can get you in big trouble. For example, say you have class with the same name in b.jar and c.jar, that is used by e.jar. Which one gets loaded? If you go down this road, then I am afraid you will start getting strange ClassCastExceptions at some point, that will be harder and harder to debug..
If you have to do this, then you could do something like
Better to reorganize your classloader hierarchy, though!