Why do we need a custom class loader in java

why tomcat has its own class loader. what is the advantage of having a custom classloader

+6
java
source share
3 answers

It isolates the various web applications deployed in the container; that is, the behavior of the web application will not depend on (un) deploying another web application.

Each webapp sees only its own classes, and not those provided by other applications. This allows different webapps to use different versions of the same class. Deploying multiple web applications would be a nightmare without this isolation.

Similarly, OSGI packages get their own class loaders, so different packages can use different versions of the same plugin. Again, this isolation makes it less likely that adding a plugin (with its depot libraries) will affect other plugins in the system.

+12
source share

Tomcat (and other application containers) should be able to handle loading classes from WAR files, etc. How could you do this without using custom classloaders?

EDIT: Basically, you need custom class loaders if you need to load classes or resources in β€œunusual” ways ... for example, from an EAR or WAR file. As another example, you can load classes from a database or from some secure repository.

+8
source share

I worked on the system when I had a class loader loading classes from a distributed database. Thus, you can change your code, compile it and give the compiler a dump of it in the database, then anyone who restarted their system would immediately download it (this was for clients in a distributed client / server system, where administrators could create their own screen modules β€œon the fly” and pushing them to customers).

This one had problems, by the way, a great theory, but I cannot recommend it.

+3
source share

All Articles