2013-03-26 71 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()解決它。