Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unload an already loaded class in Java? [duplicate]

How to unload a class from the class loader, so that I can use the recently changed class on the fly without restarting my application (hot deployment)? Is it possible to do that?

like image 958
GuruKulki Avatar asked Jan 19 '10 18:01

GuruKulki


People also ask

How do you unload a Java class?

The only way that a Class can be unloaded is if the Classloader used is garbage collected. This means, references to every single class and to the classloader itself need to go the way of the dodo.

Can same class be loaded twice in JVM?

A class is always identified using its fully qualified name (package. classname). So when a class is loaded into JVM, you have an entry as (package, classname, classloader). Therefore the same class can be loaded twice by two different ClassLoader instances.

What is dynamic class loading in Java?

Dynamic Class Loading allows the loading of java code that is not known about before a program starts. The Java model loads classes as needed and need not know the name of all classes in a collection before any one of its classes can be loaded and run.

What is custom class loader in Java?

Java uses ClassLoader implicitly when you use new , import keyword, the jvm will use the current class's classloader to load the dependent classes, so you can use the custom classloader to load a bootstrap class explicitly by using classloader.


1 Answers

Java rebel reloads changed classes on the fly. See the jrebel website for details. I don't know that I would recommend this for a production environment though, because of performance issues. JRebel on occasion bogs things down momentarily when you've recompiled for a server.

like image 158
Jim Barrows Avatar answered Oct 27 '22 21:10

Jim Barrows