• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Custom ClassLoader which depends on more than one classloader

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 :

ClassLoader 1 loads a.jar

ClassLoader 2 loads b.jar (this depends on a.jar i.e classloader 1) so we set the parent of 2 as 1.

ClassLoader 3 loads c.jar (this depends on a.jar i.e classloader 1) so we set the parent of 3 as 1.

ClassLoader 4 loads d.jar

Now the class loader 5 which loads e.jar depends on a.jar, b.jar, c.jar

Now the class loader 6 which loads f.jar depends on a.jar, d.jar

Is it possible to reuse the 1,2,3 class loader in 5 and 6?

It is very urgent.
 
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Geoffrey
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Now the class loader 6 which loads f.jar depends on a.jar, d.jar


May a jar depend on another jar?
Depending on the usage of a jar, you might be independend from another one, aren't you?
I don't know much about classloaders, but this looks reasonable to me.

Beside this thinking, dependencies between jars are undirected, probably cyclic graphs, not trees. Isn't that a problem?
 
avaya sahu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.



Avaya.
 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

Geoffrey
 
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic