Reloader is a Java utility that provides some advanced class
loading capabilities not found in standard Java class loaders, such as
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
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:
Reloadercan be provided with a list of classes that should be loaded. Alternatively, the list of “exception” classes (to load all classes other than exceptions) can be provided. Another option is to put reloadable classes into separate packages, in which case
Reloaderwould load only classes from these packages. Standard approach with putting reloadable classes on the special class path not available to the system loader is, of course, also supported.
Reloadercan log various events, such as “before loading”, “after loading”, “parent class loader loading” and so on.
For more information on class loaders, see: