Reloader
is a Java utility that provides some advanced class
loading capabilities not found in standard Java class loaders, such as URLClassLoader
.
Reloading comes handy when a new version of a class needs to be loaded without
stopping the process where the class is running. All servlet/JSP engines and
application servers use reloading extensively. Reloading is an invaluable
feature for testing/debugging, but it is can also be useful for the production
application since it allows for hot-swapping of application components.
The main problem of using URLClassLoader
or JVM system loader for
dynamic class loading is that they cache all loaded classes in memory and JDK
does not provide API to explicitly discard these cached classes. So, a new class
loader should be created every time when a class needs to be reloaded. But,
since class loader is part of the class type (meaning that two versions of the
same class loaded by different class loaders are treated as two incompatible
data types), it is very easy to run into a problem with ClassCastException
.
The related problem is that class loaders always delegate the loading request to
the parent class loader first. It means that classes on the system class path
can’t be reloaded since the system loader (parent of all class loaders) is
always going to satisfy the request with the cached version of a class.
Reloader
cures the problems of URLClassLoader
and the
likes and provides the following capabilities:
Reloader
can be provided with a list of classes thatReloader
Reloader
canFor more information on class loaders, see: