Frage

I am working with a J2EE project,my goal is to Monitor/Configure web application in the application server(Glassfish 3.1.2).For that I hope to use Mbeans. I registered my MBean as below,

MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
UsageMonitor UsagemBean = new UsageMonitor(0,0,0,0);
ObjectName name = new ObjectName("com.journaldev.jmx:type=UsageMonitor");                  
mbs.registerMBean(UsagemBean, name);

This MBean can be Monitor with JConsole(No problem working well). *How can I access this registered MBean from another java Class?*Below is the way I used to access MBean "java.lang:type=Memory" from different class it worked. And also If anyone can give a idea about how to access the MBeans from JOLOKIA it would be a great help. Thank You!.

 J4pClient j4pClient = new J4pClient("http://localhost:8080/jolokia");
 J4pReadRequest req = new J4pReadRequest("java.lang:type=Memory”,  "HeapMemoryUsage");
 req.setPath("used");
 J4pReadResponse resp = j4pClient.execute(req);
 System.out.println(resp.getValue());
War es hilfreich?

Lösung

check whether in "localhost:7001/jolokia/list" contain your mbean.if not the way you follow to register mbean is not correct.

You can refer the following tutorial. The way you have registered and create the mbean may have problems. check this out

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top