知识库--WebappClassLoader(47)
2016-12-11 18:24
405 查看
The WebappClassLoader Class
The org.apache.catalina.loader.WebappClassLoader class represents the class loader reponsible for loading the classes used in a web application. WebappClassLoader extends the java.net.URLClassLoader class, the class we used for loading Java classes .
WebappClassLoader was designed for optimization and security in mind. For example, it caches the previously loaded classes to enhance performance. It also caches the names of classes it has failed to find, so that the next time the same classes are requested to be loaded, the class loader can throw the ClassNotFoundException without first trying to find them. WebappClassLoader searches for classes in the list of repositores as well as the specified JAR files.
With regard of security, the WebappClassLoader will not allow certain classes to be loaded. These classes are stored in a String array triggers and currently has one member:
Also, you are not allowed to load classes belonging to these packages and subpackages under them, without first delegating to the system class loader:
Caching
For better performance, classes that are loaded are cached so that the next time a class is required, it can be taken from the cache. Caching can be done locally, meaning that the cache is managed by the WebappClassLoader instance. In addition,* the java.lang.ClassLoader maintains a Vector of previously loaded classes to prevent those classes from being garbage-collected*. In this case, caching is managed by the super class.//超类管理缓存
Each class that may be loaded by WebappClassLoader is referred to as a resource. A resource is represented by the org.apache.catalina.loader.ResourceEntry class. A ResourceEntry instance holds the byte array representation of the class, the last modified date, the Manifest(if the resource if from a JAR file), etc.
All cached resources are stored in a HashMap called resourceEntries.
All resources that were not found are stored in another HashMap called notFoundResources.
When loading a class, the WebappClassLoader class applies these rules:
The org.apache.catalina.loader.WebappClassLoader class represents the class loader reponsible for loading the classes used in a web application. WebappClassLoader extends the java.net.URLClassLoader class, the class we used for loading Java classes .
WebappClassLoader was designed for optimization and security in mind. For example, it caches the previously loaded classes to enhance performance. It also caches the names of classes it has failed to find, so that the next time the same classes are requested to be loaded, the class loader can throw the ClassNotFoundException without first trying to find them. WebappClassLoader searches for classes in the list of repositores as well as the specified JAR files.
With regard of security, the WebappClassLoader will not allow certain classes to be loaded. These classes are stored in a String array triggers and currently has one member:
private static final String[] triggers = {"javax.servlet.Servlet"}
Also, you are not allowed to load classes belonging to these packages and subpackages under them, without first delegating to the system class loader:
private static final String[] packageTriggers={ "javax", "org.xml.sax", "org.w3c.dom", "org.apache.xerces", "org.apache.xalan" };
Caching
For better performance, classes that are loaded are cached so that the next time a class is required, it can be taken from the cache. Caching can be done locally, meaning that the cache is managed by the WebappClassLoader instance. In addition,* the java.lang.ClassLoader maintains a Vector of previously loaded classes to prevent those classes from being garbage-collected*. In this case, caching is managed by the super class.//超类管理缓存
Each class that may be loaded by WebappClassLoader is referred to as a resource. A resource is represented by the org.apache.catalina.loader.ResourceEntry class. A ResourceEntry instance holds the byte array representation of the class, the last modified date, the Manifest(if the resource if from a JAR file), etc.
public class ResourceEntry{ public long lastModified = -1; public byte[] binaryContent = null; public Class loadedClass = null; //URL source from where the oject was loaded public URL source = null; public URL CodeBase = null; public Manifest manifest = null; public Certificate[] certificates = null; }
All cached resources are stored in a HashMap called resourceEntries.
All resources that were not found are stored in another HashMap called notFoundResources.
When loading a class, the WebappClassLoader class applies these rules:
1 All previously loaded classes are cached, so first check the local cache. 2 If not found in the local cache,check in the cache,i.e. by calling the findLoadedClass of the java.lang.ClassLoader class. 3 If not found in both caches, use the system's class loader to prevent the web application from overriding J2EE class. 4 If SecurityManager is used, check if the class is allowed to be loaded.If not,throw a ClassNotFoundException. 5 If the dalagate flag is on or if the class to be loaded belongs to the package name in the package trigger, use the parent class loader to load the class. If the parent class loader is null, use the system class loader. 6 Load the class from the current repositories. 7 If the class is not found in the current repositories, and if the delegate flag is not on, use the parent class loader. If the parent class loader is null,use the system class loader. 8 If the class is still not found, throw a ClassNotFoundException.
相关文章推荐
- As3.0 xml + Loader应用代码
- 基于jquery的lazy loader插件实现图片的延迟加载[简单使用]
- AS3.0 实例学习 熟悉addChild和removeChild在不同的swf之间的运用,以及loader的用法
- 借用Google的Javascript API Loader来加速你的网站
- Zend Framework教程之Loader以及PluginLoader用法详解
- ioncube_loader_win_5.2.dll的错误解决方法
- SQL LOADER错误小结
- SqlLoader怎么使用
- Windows下的PHP 5.3.x安装 Zend Guard Loader教程
- PHP5.3安装Zend Guard Loader图文教程
- 使用 angular-async-loader 来实现异步加载 angular 模块
- Zend Framework使用Zend_Loader组件动态加载文件和类用法详解
- JS文件装载器(Eve Js Loader)
- Oracle sql loader的应用(二)
- Oracle sql loader的应用(一)
- Oracle sql loader的基本概念
- flash as3 加载外部swf jpg gif png loader urlloader的通用代码
- Loader,AsyncTaskLoader,CursorLoader,LoaderManager 相关
- android developer tiny share-20160927
- android developer tiny share-20160928