agapple

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            13 Posts :: 1 Stories :: 1 Comments :: 0 Trackbacks

          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實例是一對多的關系。

          2. jboss classloader機制
             

          <mbean code="org.jboss.management.j2ee.LocalJBossServerDomain"
                name
          ="jboss.management.local:j2eeType=J2EEDomain,name=Manager">
                
          <attribute name="MainDeployer">jboss.system:service=MainDeployer</attribute>
                
          <attribute name="SARDeployer">jboss.system:service=ServiceDeployer</attribute>
                
          <attribute name="EARDeployer">jboss.j2ee:service=EARDeployer</attribute>
                
          <attribute name="EJBDeployer">jboss.ejb:service=EJBDeployer</attribute>
                
          <attribute name="RARDeployer">jboss.jca:service=RARDeployer</attribute>
                
          <attribute name="CMDeployer">jboss.jca:service=ConnectionFactoryDeployer</attribute>
                
          <attribute name="WARDeployer">jboss.web:service=WebServer</attribute>
                
          <attribute name="CARDeployer">jboss.j2ee:service=ClientDeployer</attribute>
                
          <attribute name="MailService">jboss:service=Mail</attribute>
                
          <attribute name="JMSService">jboss.mq:service=DestinationManager</attribute>
                
          <attribute name="JNDIService">jboss:service=Naming</attribute>
                
          <attribute name="JTAService">jboss:service=TransactionManager</attribute>
                
          <attribute name="UserTransactionService">jboss:service=ClientUserTransaction</attribute>
                
          <attribute name="RMI_IIOPService">jboss:service=CorbaORB</attribute>
             
          </mbean>


             首先看一下各種類型的deployer。不同的deployer是根據文件的后綴進行區分。MainDeployer起到一個controller的作用,根據不用的后綴分發到不同的deployer進行處理。如果是*.ear,則會由EARDeployer進行載入。
          應用的加載時一個 Top Level Deployer + Top Level Ucl。 舉個例子,比如發布一個a.ear應用,ear應用中會包含一個*.war。這時候就會涉及deployer選擇問題。jboss采取的原則就是按Top Level,根據最頂層的應用選擇deployer,繼而也有了top level ucl的概念。由頂級的ucl來加載整個應用。這里需要注意的是war的部署有點特別。它只是將自身添加到ucl的classpath域中,而war下的WEB-INF/lib/*.jar,則是由WebAppClassloader來加載。可調整ear下的 META-INF/jboss-service.xml中的UseJbossWebLoader屬性。如果設置為true,故名思義就是用ucl來加載war下的jar包。否則就是采用獨立的classloader加載。
             再看一下ucl的加載過程,首先會調用倉庫去loadclass,倉庫在查找無果的情況下會回調各自的UCL去加載本地庫。


          3. jboss scope配置

          ClassLoadingConfiguration一書中描述:

          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才有效。這也與前面 TOP level UCL + TOP Devloper相對應。
              

              針對.sar,你可以在jboss-service.xml中,添加如下配置:
          <server>  
              
          <loader-repository> com.example:loader=unique-archive-name </loader-repository>  
          </server>

                  
              針對.ear,你可以在jboss-app.xml添加如下配置:
              
          <jboss-app>  
            
          <loader-repository>com.example:loader=unique-archive-name</loader-repository>  
          </jboss-app>
              
              針對 .war,你可以在jboss-web.xml添加如下配置:
              
          <jboss-web>
          <class-loading java2ClassLoadingCompliance='true'>  
                 
          <loader-repository>    
                       com.example:loader=unique-archive-name  
                       
          <loader-repository-config>  
                           java2ParentDelegaton=true  
                       
          </loader-repository-config>  
                
          </loader-repository>    
           
          </class-loading>
          </jboss-web>
             
             注意,在最新的4.2.1版本中,<class-loading>標簽已經不再使用,你可以直接配置:
          <jboss-web>    
              
          <loader-repository> com.example:loader=unique-archive-name </loader-repository>    
          </jboss-web>

              針對這兩種方式的配置,4.0.5版本都支持。  
                
              針對典型的ear+war應用,*.ear/META-INF/jboos-service.xml,用于調整war的加載方式。
           
          <!-- 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>  
              配置java2ClassLoadingCompliance為true,則表明是選擇parent first。典型的classloader的雙親委托模型,否則是采用child first,先從自身加載,找不到再相父類請求。
              配置UseJBossWebLoader為false,則webapp的加載通過獨立于jboss的classloader進行加載。


          Blog : http://agapple.javaeye.com/  歡迎訪問
          posted on 2008-10-23 14:08 agapple 閱讀(4086) 評論(0)  編輯  收藏 所屬分類: java服務器
          主站蜘蛛池模板: 灌阳县| 龙岩市| 大厂| 涟水县| 五峰| 武平县| 无锡市| 曲阜市| 平阴县| 樟树市| 安徽省| 栾城县| 太白县| 明溪县| 福清市| 江山市| 新竹县| 宁乡县| 阜南县| 英吉沙县| 五常市| 辽源市| 新闻| 德江县| 时尚| 衡东县| 辽阳县| 南岸区| 吉木萨尔县| 泽普县| 射阳县| 寿光市| 汶川县| 唐山市| 探索| 双柏县| 施甸县| 资中县| 上蔡县| 衡阳市| 丰县|