开发者

How to get the class loader ObjectName from a JavaEE application under JBoss 5.x

开发者 https://www.devze.com 2022-12-08 10:51 出处:网络
Our JavaEE application has a services which is responsible for installation and start up of other services depending on the configuration stored in a database. Services are installed using the

Our JavaEE application has a services which is responsible for installation and start up of other services depending on the configuration stored in a database. Services are installed using the

ServiceControllerMBean.install(
    org.w3c.dom.Element element,
    javax.management.ObjectName objectName)

method. This method requires a class loader ObjectName as the second argument. Under JBoss 4.x we used the following hack to get the class loader name:

final ServiceControllerMBean serviceController = 
    (ServiceControllerMBean) MBeanProxy.get(
        ServiceControllerMBean.class,
        ServiceControllerMBean.OBJECT_NAME, s开发者_如何学Cerver);

final ClassLoader = serviceController.getClass().getClassLoader();

final ObjectName loader = new ObjectName(
    "jmx.loading:UCL=" + Integer.toHexString(classLoader.hashCode()))

However this does not work under JBoss 5.x for the class loader naming has been changed.

Could somebody advise a way to get the class loader name under JBoss 5.x?

Thank you in advance


Found this documentation for the issue:

ClassLoader Configuration

Classloading UseCase

Nice to get an insight view.

Finally a nice Forum Thread i found:

http://www.coderanch.com/t/464514/JBoss/Class-Loading-Configuration

Additional Info:

ClassLoader loader = Thread.currentThread().getContextClassLoader();
System.out.println( loader );  // sun.misc.Launcher$AppClassLoader@a12a00
loader = ThreadClassloader.class.getClassLoader();
System.out.println( loader );  // sun.misc.Launcher$AppClassLoader@a12a00

Hpe this helps you to get more Information out of your code.


After doing a little bit of research on the subject I got an answer to my question. Though I do not like it very much for it looks more like another hack. But I will use it unless somebody suggests a more elegant solution. So:

In JBoss 5.1.0 (the one I am playing with) class loaders are registered with names like:

jboss.classloader:id="vfsfile:<archive-file-name>"

At the same time the string representation of a class loader object returned by the toString() method looks like this:

BaseClassLoader@<memory-address>{vfsfile:<archive-file-name>}

Therefore it is possible to extract the archive-file-name from the class loader string representation and construct an appropriate ObjectName from it.

0

精彩评论

暂无评论...
验证码 换一张
取 消