|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.ClassLoader | +--org.apache.java.lang.AdaptiveClassLoader
A class loader that loads classes from directories and/or zip-format file such as JAR file. It tracks the modification time of the classes it loads to permit reloading through re-instantiation.
When the classloader reports its creator that one of the classes it
has loaded has changed on disk, it should discard the classloader
and create a new instance using reinstantiate
.
The classes are then reloaded into the new classloader as required.
The classloader can also load resources, which are a means for packaging application data such as images within a jar file or directory.
The classloader always first tries to load classes and resources from the system, and uses it's own path if that fails. This is also done if an empty repository is passed at construction.
How autoreload works:
The Java VM considers two classes the same if they have the same
fully-qualified name and if they were loaded from the same
ClassLoader
.
There is no way for a classloader to 'undefine' a class once it has been loaded. However, the servlet engine can discard a classloader and the classes it contains, causing the
The JServServletManager
creates a new instance of
the classloader each time it detects that any of the loaded classes
have changed.
Before terminating, all servlets are destroyed.
According to the Java Language Specification (JLS), classes may
be garbage-collected when there are no longer any instances of that
class and the java.lang.Class
object is finalizable.
It is intended that this be the case when a JServClassLoader
is discarded.
Many VM releases did not implement class garbage collection
properly. In such a VM, the memory usage will continue to grow if
autoreloading is enable. Running the VM with
-verbosegc
(or the corresponding option for
non-Javasoft VMs) may give some debugging information.
It is important that the destroy
method be
implemented properly, as servlets may be destroyed and
reinitialized several times in the life of a VM.
Constructor Summary | |
AdaptiveClassLoader(java.util.Vector classRepository)
Creates a new class loader that will load classes from specified class repositories. |
Method Summary | |
java.net.URL |
getResource(java.lang.String name)
Find a resource with a given name. |
java.io.InputStream |
getResourceAsStream(java.lang.String name)
Get an InputStream on a given resource. |
protected java.lang.Class |
loadClass(java.lang.String name,
boolean resolve)
Resolves the specified name to a Class. |
AdaptiveClassLoader |
reinstantiate()
Re-instantiate this class loader. |
boolean |
shouldReload()
Check whether the classloader should be reinstantiated. |
boolean |
shouldReload(java.lang.String classname)
Check to see if a given class should be reloaded because of a modification to the original class. |
Methods inherited from class java.lang.ClassLoader |
defineClass,
defineClass,
defineClass,
definePackage,
findClass,
findLibrary,
findLoadedClass,
findResource,
findResources,
findSystemClass,
getPackage,
getPackages,
getParent,
getResources,
getSystemClassLoader,
getSystemResource,
getSystemResourceAsStream,
getSystemResources,
loadClass,
resolveClass,
setSigners |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public AdaptiveClassLoader(java.util.Vector classRepository) throws java.lang.IllegalArgumentException
classRepository
- An set of File classes indicating
directories and/or zip/jar files. It may be empty when
only system classes are loaded.Method Detail |
public boolean shouldReload(java.lang.String classname)
className
- The name of the class to check for modification.public boolean shouldReload()
The classloader must be replaced if there is any class whose origin file has changed since it was last loaded.
public AdaptiveClassLoader reinstantiate()
This method creates a new instance of the class loader that will load classes form the same path as this one.
protected java.lang.Class loadClass(java.lang.String name, boolean resolve) throws java.lang.ClassNotFoundException
name
- the name of the desired Class.resolve
- true if the Class needs to be resolved;
false if the virtual machine just wants to determine
whether the class exists or notpublic java.io.InputStream getResourceAsStream(java.lang.String name)
The JServClassLoader translate the resource's name to a file or a zip entry. It looks for the resource in all its repository entry.
name
- the name of the resource, to be used as is.Class.getResourceAsStream(String)
public java.net.URL getResource(java.lang.String name)
This classloader looks for the resource only in the directory repository for this resource.
name
- the name of the resource, to be used as is.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |