2013-03-26 73 views
0

我尝试使用下面的代码来访问JBoss的4.2版的MBean注册为的MBean “jboss.web:类型=经理,路径= /,主机=本地主机” 没有找到

jboss.web:type=Manager,path=/,host=localhost 

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost"); 
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions"); 

但这码不断抛出以下异常:

javax.management.InstanceNotFoundException : jboss.web:type=Manager,path=/,host=localhost is not registered. 

在行吟诗人r我可以通过jmx控制台查看和使用这个bean ... // localhost:8080/jmx-console/- MBean可用。

Screenshot

是还有什么必要通过代码来访问同一个MBean?

回答

1

发现...

ObjectName name = new ObjectName("jboss.web:type=Manager,path=/,host=localhost"); 
this.sessions = new Long((Integer) MBeanServerLocator.locateJBoss().getAttribute(name, "activeSessions")); 

我必须找到合适的MBeanServer ... MBeanServerLocator.locateJBoss()解决它。