JavaUser
JavaUser

Reputation: 26344

In Java, what is the use case for new or enhancing the class loader?

In Java, we know class loader is a JVM system which loads the classes into JVM for executiion. When I run a simple Java class , it is getting loaded and executed by the run time system. Here I am not doing anything with respect to the class loading. But I can see, there are various projects in which they are writing a custom class loader or enhancing the existing class loaders . Please let me know the production time use case where class loader enhancement or new class loader is required.

Upvotes: 2

Views: 202

Answers (1)

Tarun
Tarun

Reputation: 3165

The few use case that I can think of right now:

  1. You can use custom classloader to replace implementation during runtime (i.e without restarting server). It is being used heavily by JRebel
    https://www.jrebel.com/blog/how-to-reload-java-classes-at-runtime

  2. Tomcat uses classloader to separate different webapps object scope at runtime.
    How Tomcat Classloader separates different Webapps object scope in same JVM?

  3. OSGI uses classloader to load bundles.
    Java classloader usage in OSGi

Upvotes: 5

Related Questions