The DynamicClassLoadingChain builds a chain of URLClassLoaders for the purpose of retrieving classes from all loaders while keeping individual loaders separate for addition and updating. The loaders registered are called "subloaders". New subloaders can be added at runtime, where each new classloader has the most recently added classloader as it's parent. So using the most recently added classloader - the "top loader" retrievable by {@link #getTopLoader()} - you can load all classes provided by all class loaders in the chain.
Also at runtime individual class loaders in the chain may be replaced. At adding time you can provide a key with each new class loader that you can use later to address the loader to be replaced. Use method {@link #updateSubLoader(String,URL[])} for this. Replacing a class loader will implicitlyrecreate all class loaders down the child chain, but leave all class loaders up the parent chain untouched.
When adding a loader you can declare it "static" (when using {@link #updateSubLoader(String,URL[],boolean)} and setting the last param to true). These loaders will beadded to the chain in a way that will prevent them from being updated and rebuilt. They are inserted to the chain before all non-static loaders and updating or removing them will cause an {@link IllegalStateException} to be thrown. You can use static loaders for classes that need to be static in the classpath for theirfunctionalities to work. For example if you have a singleton class that maintains state, rebuilding the loader of the class will drop the singleton instance and by the next use of it a new one will be created. By setting the loader to static you prevent such problems.
|
|