jboss classloader加载机制

本文探讨了JBoss Unified Class Loader (UCL) 的工作原理及其与部署模块之间的关系。详细介绍了UCL如何实现热部署需求,以及通过UnifiedLoaderRepository3管理类和资源。此外,还解释了不同配置文件(如META-INF/jboss-service.xml和WEB-INF/jboss-web.xml)中scope配置的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 参数配置:

<!-- Get the flag indicating if the normal Java2 parent first class
           loading model should be used over the servlet 2.3 web container first
           model.
      -->
      <attribute name="Java2ClassLoadingCompliance">false</attribute>
      <!-- A flag indicating if the JBoss Loader should be used. This loader
           uses a unified class loader as the class loader rather than the tomcat
           specific class loader.
           The default is false to ensure that wars have isolated class loading
           for duplicate jars and jsp files.
      -->
      <attribute name="UseJBossWebLoader">false</attribute>

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

 

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

<class-loading java2ClassLoadingCompliance='true'>
       <loader-repository> 
             dot.com:loader=unique-archive-name
             <loader-repository-config>
                 java2ParentDelegaton=true
             </loader-repository-config>
      </loader-repository> 
 </class-loading>

 

或者

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

 

   

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值