jboss classloader加载机制

简介:

1. 概念

 

UCL : org.jboss.mx.loading.UnifiedClassLoader3 ,它继承标准的java.net.URLClassLoader,覆盖了标准parent delegation模型以使用共享class和资源仓库

 

仓库(responsitory): org.jboss.mx.loading.UnifiedLoaderRepository3。

 

平面模型:为了热deploy模块的需要,JBoss实现了自己的类装载器UnifiedClassLoader3,一般来说,一个顶层的deployment就有一个UnifiedClassLoader3实例为之工作。一个deployment所装载的类,其他 deployment是可见的。全局唯一的UnifiedLoaderRepository3实例用于管理这些类,以及装载它们的UnifiedClassLoader3。UnifiedLoaderRepository3实例和

UnifiedClassLoader3实例是一对多的关系。

 

写道
There are two levels of scoping, isolation from other deployments, and isolation that overrides the loading of JBoss server classes. With nested modules, only the top level file may specify class loader scoping. If you have a .ear file containing other modules, only scoping specified in the .ear 's META-INF/jboss-app.xml is used. This also applies for any other deployment which contains sub-deployments. For example, if a .sar contains a .war deployment, only the .sar META-INF/jboss-service.xml scoping has effect.

 意思是说,scope配置只能是顶级下的配置,比如一个.sar中包含.war都配置了scope,只有.sar下的 META-INF/jboos-service.xml才有效。

 

META-INF/jboos-service.xml 参数配置:

1.<!-- Get the flag indicating if the normal Java2 parent first class  
2.           loading model should be used over the servlet 2.3 web container first  
3.           model.  
4.      -->  
5.      <attribute name="<span style="color: rgb(255, 0, 0);">Java2ClassLoadingCompliance</span>">false</attribute>  
6.      <!-- A flag indicating if the JBoss Loader should be used. This loader  
7.           uses a unified class loader as the class loader rather than the tomcat  
8.           specific class loader.  
9.           The default is false to ensure that wars have isolated class loading  
10.           for duplicate jars and jsp files.  
11.      -->  
12.      <attribute name="<span style="color: rgb(255, 0, 0);">UseJBossWebLoader</span>">false</attribute>  

配置UseJBossWebLoader为false,则webapp的加载通过独立于jboss的classloader进行加载。

 

WEB-IN/jboss-web.xml , 两种配置方式:


1.<class-loading java2ClassLoadingCompliance='true'>  
2.       <loader-repository>   
3.             dot.com:loader=<span style="color: rgb(255, 0, 0);">unique-archive-name</span>  
4.             <loader-repository-config>  
5.                 java2ParentDelegaton=true  
6.             </loader-repository-config>  
7.      </loader-repository>   
8. </class-loading>  

或者


1.<class-loading java2ClassLoadingCompliance='true'></class-loading>

对于第一种配置,webapp将使用JBoss隔离的UCL作为Classloader,并且是否是parent load模型是由其中的java2ParentDelegaton参数决定,java2ClassLoadingCompliance='true'属性将被忽略。

java2ParentDelegaton='true'或者'false'决定了是否采用parent first/child first模型。

相关文章
|
Java 关系型数据库 应用服务中间件