`
yangzb
  • 浏览: 3500423 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

JBOSS ClassLoadingConfiguration

    博客分类:
  • Java
阅读更多

Discussion

By default JBoss (prior to version 3.2) uses a flat class loading model that avoids the need to redundantly include classes in different layers. WAR files would only have the web contents and servlets, EJBs their interfaces, implementations and types, etc. Canonical packaging works correctly with this model.

However, if you have applications that cannot share classes because of version conflicts, then you need to isolate the classes from other deployments. Without isolation, common errors seen are ClassCastException ? , IllegalAccessErrors ? , VerifyErrors ? and in general, strange behavior that changes as new deployments are added and removed.

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.

 

Specifying Isolation

For .ear files, in your jboss-app.xml , add the following descriptor fragment construct to enabled scoped class loading:

 

<jboss-app>
   <loader-repository> 
   com.example:archive=unique-archive-name 
   </loader-repository> 
</jboss-app>

For .war files, in your jboss-web.xml , the following template applies:

 
<jboss-web>
   <class-loading> 
      <loader-repository> 
      com.example:archive=unique-archive-name 
      </loader-repository> 
   </class-loading>
</jboss-web> 

 

Note: As of at least JBoss 4.2.1, the <class-loading> tag appears to no longer be supported as isolation is ignored. Instead, the following configuration appears to accomplish the same goal:

 
<jboss-web>
   <loader-repository> 
      com.example:archive=unique-archive-name 
   </loader-repository> 
</jboss-web> 
Interestingly enough, 4.0.5 seems to support both configurations.

 

For .sar files, in your jboss-service.xml , the following template applies:

 
<server>
	<loader-repository>
		com.example:archive=unique-archive-name 
	</loader-repository>
</server>

The <loader-repository> elements must be correctly placed within the respective <jboss-app> , <jboss> and <jboss-web> XML elements. Check the corresponding DTD found in the docs/dtd directory of the distribution for the complete content model.

The com.example:archive=unique-archive-name strings are JMX ObjectName strings. These have no particular significance other than that they must be unique. It might be useful to use the same name as used for the .ear , .war , or .sar file. For example, for a petstore.ear file, use: com.example:loader=petstore.ear as the repository name.

The loader-repository ObjectName will appear in the JMX-Console (http://localhost:8080/jmx-console/ ). This MBean is great for debugging any class-loading issues which might arise. The hierarchical loaders created from the repository wll appear together under the loader-repository domain name, com.example in the example.

 


 

Isolation with Overriding Server Classes

Use the following constructs to enabled scoped class loading with the deployment classes overriding the server classes.

For jboss-app.xml :

 

 
<jboss-app>
  <loader-repository> 
  com.example:archive=unique-archive-name 
     <loader-repository-config> 
     java2ParentDelegation=false 
     </loader-repository-config> 
  </loader-repository>
</jboss-app>

For jboss-web.xml :

<jboss-web>
 <class-loading java2ClassLoadingCompliance="false">
 <loader-repository>
 com.example:archive=unique-archive-name
 <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
 </loader-repository>
 </class-loading>
 ...
Note: See comment above regarding web class loader isolation.

For jboss-service.xml :

<server>
 <loader-repository>
 com.example:archive=unique-archive-name
 <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
 </loader-repository>
 ...

The isolated EAR or WAR repository will load its libraries in this order:

 

  1. WEB-INF/lib (for WARs)
  2. libraries in server/default/lib
  3. tomcat-libraries in server/default/deploy/jbossweb-tomcat50.sar (jboss-3.2.6).
The libraries in server/default/lib get mixed together with jbossweb-tomcat50.sar in no specific order (for details look into the loader-repository in the JMX-console).

 

The Web Container

In jboss-3.2.3, the jbossweb-tomcat41.sar is configured to use a unified class loader as the web application class loader. This is controlled by the UseJBossWebLoader attribute in the jbossweb-tomcat41.sar/META-INF/jboss-service.xml descriptor. The use of a unified class loader means that the classes available in the war inside of the WEB-INF/classes and WEB-INF/lib are incorporated into the default shared class loader repository. This may not be what you want as its contrary to the default servlet 2.3 class loading model and can result in sharing of classes/resources between web applications. You can disable this by setting this attribute to false.

 

The Web Container from 4.0.2

From 4.0.2 JBoss has changed to the Servlet spec classloading model, i.e. it uses the Tomcat classloader. See the related JIRA Task

 

Simplified Configuration from 3.2.4

From JBoss-3.2.4 the EAR deployer provides a simplified version of the isolation. You can configure all your ears to be in isolated classloader spaces using call by value for remote interfaces.

The EARDeployer is configured in conf/jboss-service.xml for versions 3.x and in deploy/ear-deployer.xml for versions 4.x+

 

 <!-- EAR deployer, remove if you are not using Web layers -->
 <mbean code="org.jboss.deployment.EARDeployer" name="jboss.j2ee:service=EARDeployer">
 <!-- Isolate all ears in their own classloader space -->
 <attribute name="Isolated">true</attribute>
 <!-- Enforce call by value to all remote interfaces -->
 <attribute name="CallByValue">true</attribute>
 </mbean>

 

Accessing EJBs in isolated ears

If you want to make JNDI lookups across EARs that are isolated, you need to force marshalling of the lookup, e.g. if you have the following ejb-ref in your ejb-jar.xml that references an EJB in an isolated WAR

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE ejb-jar PUBLIC
 "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
 "http://java.sun.com/dtd/ejb-jar_2_0.dtd">

 <ejb-jar>
 <enterprise-beans>
 <session>
 <ejb-name>SessionA</ejb-name>
 <home>org.jboss.test.isolation.interfaces.a.SessionAHome</home>
 <remote>org.jboss.test.isolation.interfaces.a.SessionA</remote>
 <ejb-class>org.jboss.test.isolation.ejb.a.SessionAEJB</ejb-class>
 <session-type>Stateless</session-type>
 <transaction-type>Container</transaction-type>
 <ejb-ref>
 <ejb-ref-name>ejb/SessionB</ejb-ref-name>
 <ejb-ref-type>Session</ejb-ref-type>
 <home>org.jboss.test.isolation.interfaces.b.SessionBHome</home>
 <remote>org.jboss.test.isolation.interfaces.b.SessionB</remote>
 </ejb-ref>
 </session>
 </enterprise-beans>
 </ejb-jar>

In jboss.xml use the full scheme to define the lookup:

 <?xml version="1.0" encoding="UTF-8"?>

 <jboss>
 <enterprise-beans>
 <session>
 <ejb-name>SessionA</ejb-name>
 <ejb-ref>
 <ejb-ref-name>ejb/SessionB</ejb-ref-name>
 <jndi-name>jnp://${jboss.bind.address:localhost}:1099/SessionB</jndi-name>
 </ejb-ref>
 </session>
 </enterprise-beans>
 </jboss>

You can also use the full scheme in lookups from non-EJB clients such as standalone applications or JSP pages. In this case you would be encoding deployment knowledge into the code - the applications will always use call-by-value even if your needs change. If you are retro-fitting classloader isolation you may also have a lot of lookup code to change, although you should probably have used a constant or lookup service to hold the actual name.

An alternative is to force all JNDI lookups to be call-by-value, which you can do in <server>/deploy/naming-service.xml (This used to reference <server>/conf/jboss-service.xml, which is WRONG for 4.0.3) in the section headed JNDI. Change the jboss:service=Naming bean definition so that the CallByValue ? attribute reads:

 

<mbean code="org.jboss.naming.NamingService"
      name="jboss:service=Naming"
      xmbean-dd="resource:xmdesc/NamingService-xmbean.xml">

  ...

  <attribute name="CallByValue">true</attribute>

  ...

</mbean>

This is indiscriminate - JBoss will be unable to optimise any JNDI calls any more, but may be appropriate in some circumstances.

 

Performance note - Call By Value

The use of call by value and marshalling is very inefficient. It typically means method invocations take 10 times the cpu. Why? Compare Call By Value with Call By Reference

 

Call By Reference

  1. caller does ejb.someMethod()
  2. invocation is passed through ejb container
  3. container does bean.someMethod()
  4. result is returned to the caller

 

Call By Value

  1. caller does ejb.someMethod()
  2. invocation is marshalled - the parameters are turned into ObjectStream ? (a
    byte[]
    )
  3. container with a different classloader unmarshalls -
    byte[]
    -> java Objects - including classloading
  4. invocation is passed through ejb container
  5. container does bean.someMethod()
  6. result is marshalled - the return value is turned into ObjectStream ?
  7. result is unmarshalled using the caller's classloader -
    byte[]
    -> java Object
  8. result is return to the caller

The marshalling and unmarshalling uses a lot of cpu.

 

Related

JBossClassLoadingUseCases
Preloading classes at startup
Debugging class loading issues

 

Referenced by

GetClassNotFoundExceptionOrNoClassDefFoundError
HowCanIDynamicallyLoadClassesWithinAnMBean
JBoss5AndMyFaces
JBossESBDeploymentStrategies
JBossFrequentlyAskedQuestions
Main
RulesTomcat

cant di this in 3.2.7

分享到:
评论

相关推荐

    Jboss项目部署文档

    Jboss 项目部署文档 Jboss 项目部署文档是指在 Jboss 服务器上部署项目的详细步骤,包括环境变量的配置、项目打包、配置文件的修改、JNDI 的配置等。以下是 Jboss 项目部署文档的详细知识点: 一、环境变量配置 ...

    jboss 下载(httpwww.jboss.org)

    【JBoss 应用服务器详解】 JBoss 是一个开源的、基于 J2EE(Java 2 Platform, Enterprise Edition)的应用服务器,由全球开发者社区共同维护和开发。它最初以 LGPL 许可协议发布,允许商业应用免费使用。2006年,...

    JBOSS,JBoss安装部署

    【JBOSS,JBoss安装部署】 JBoss是Red Hat公司开发的一款开源的应用服务器,它基于Java EE(Enterprise Edition)规范,提供了全面的企业级应用程序部署和管理解决方案。本篇文章将详细讲解JBoss的安装和部署过程,...

    jboss7.1 linux版本

    JBoss AS 7.1.0.Final是在Linux环境下运行的一款开源Java应用服务器,由Red Hat公司维护。这个版本发布于2012年,它引入了许多改进和新特性,旨在提供更快的启动速度、更高的性能以及更好的模块化。在这个环境中,...

    在jboss上部署web应用

    【JBoss 概述】 JBoss 是一个开源的、基于Java的、全面实现了J2EE规范的应用服务器。它提供了企业级的功能,如EJB(Enterprise JavaBeans)、JMS(Java Message Service)、JTS/JTA(Java Transaction Service / ...

    在IntelliJ idea8中部署Jboss服务器图解

    "在IntelliJ IDEA 8中部署Jboss服务器图解" IntelliJ IDEA 8是 JetBrains 公司开发的一款功能强大且灵活的集成开发环境(IDE),它支持多种programming语言,包括Java、Python、Ruby、PHP等。Jboss则是一款流行的...

    MyEclipse中配置JBoss

    【标题】:“MyEclipse中配置JBoss” 在IT行业中,MyEclipse是一款深受开发者喜爱的集成开发环境(IDE),尤其对于Java EE项目开发来说,它提供了强大的支持。而JBoss则是一个开源的应用服务器,广泛用于部署和管理...

    jboss-eap-7.2.6-patch

    【JBoss EAP 7.2.6 补丁包详解】 JBoss Enterprise Application Platform (EAP) 是 Red Hat 提供的一款开源中间件,用于构建、部署和管理企业级 Java 应用程序。JBoss EAP 7.2.6 版本是一个重要的更新,包含了多个...

    jboss-4.0.5.GA.zip

    JBoss是著名的开源Java应用服务器,它基于Java EE(Enterprise Edition)规范,为开发者提供了全面的中间件服务。4.0.5.GA版本是JBoss的一个稳定版本,发布于2006年,适用于那些需要可靠且成熟的Java应用程序部署的...

    jboss配置入门,jboss的初级配置

    jboss配置入门 jboss系统是一种基于Java的应用服务器,具有高性能、可扩展、安全性强等特点。在本文中,我们将对jboss的基本配置进行介绍,包括其文件夹结构、配置文件、负载均衡配置等。 jboss文件夹结构 jboss的...

    JavaEE源代码 jboss-common

    JavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-...

    jboss热部署配置

    JBoss是一款著名的开源Java应用服务器,它提供了许多企业级服务,包括事务管理、安全性和集群功能。在开发过程中,为了提高效率,我们通常希望在不中断应用服务的情况下更新部署的应用程序,这就是所谓的“热部署”...

    jboss7ejb配置文件

    在JBoss 7及以上版本中,对EJB的配置过程相较于之前的版本有所变化,主要涉及到两个关键的配置文件:`jboss-ejb3.xml`和`ejb-jar.xml`。 `ejb-jar.xml`文件是EJB模块的标准配置文件,遵循Java EE规范。在这个文件中...

    jboss7开发部署详细文档

    本文档提供了jboss7开发和部署的详细指导,涵盖了jboss7的下载与安装、Eclipse中配置jboss7、项目部署和JNDI获取等方面的内容,旨在帮助开发者快速上手jboss7,并将jboss4.2版本平滑地移植到jboss7。

    jboss-exp.rar

    某大牛写的jboss-exp 1. 查看系统名称 java -jar jboss_exploit_fat.jar -i http://192.168.7.84:10081/invoker/JMXInvokerServlet get jboss.system:type=ServerInfo OSName 2. 查看系统版本 java -jar jboss_...

    jboss如何在windows系统服务中启动

    在IT行业中,JBoss是一个广泛使用的Java应用服务器,它提供了许多功能,如部署和管理Web应用程序、事务处理、安全管理等。对于Windows用户来说,将JBoss配置为系统服务可以实现自动启动,避免每次开机时手动开启,...

    jboss-logging-3.3.2.Final-API文档-中文版.zip

    赠送jar包:jboss-logging-3.3.2.Final.jar; 赠送原API文档:jboss-logging-3.3.2.Final-javadoc.jar; 赠送源代码:jboss-logging-3.3.2.Final-sources.jar; 赠送Maven依赖信息文件:jboss-logging-3.3.2.Final....

Global site tag (gtag.js) - Google Analytics