InstanceNotFoundException: java.lang:type=Runtime

I am puzzled by this behavior of my Mbean Object. It displays all stats on one server, and on the other one, throws the InstanceNotFoundException: java.lang:type=Runtime... Both servers are running the same version and set up for everything...

This is the code snippet:

java.lang.Long upTime = new Long(0);

try {

ArrayList servers = MBeanServerFactory.findMBeanServer(null);

if (servers == null)

throw new Exception("No MBeanServer found.");

MBeanServer server = (MBeanServer)servers.get(0);

ObjectName javaRuntime = new ObjectName("java.lang:type=Runtime");

//Error thrown by the line below:

upTime = (java.lang.Long) server.getAttribute(javaRuntime, "Uptime");

} catch (Exception e) {

e.printStackTrace();

}

Could someone please guide me to the mistake here?

Your help is greatly appreciated!

The exact exception thrown is:

javax.management.InstanceNotFoundException: java.lang:type=Runtime

at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(Defaul

tMBeanServerInterceptor.java:1010)

at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(De

faultMBeanServerInterceptor.java:627)

at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.ja

va:659)

at com.hns.rpms.mib.k_rpmsConfig.k_get(k_rpmsConfig.java:230)

at com.hns.rpms.mib.v_rpmsConfig.v_get(v_rpmsConfig.java:209)

at com.snmp.agent.lib.SRSNMPAgent.handleGetRequestEvent(SRSNMPAgent.java

:1219)

at com.snmp.agent.lib.SRSNMPAgent.access$900(SRSNMPAgent.java:59)

at com.snmp.agent.lib.SRSNMPAgent$SAMLThread.run(SRSNMPAgent.java:1879)

[1716 byte] By [CathyGrega] at [2007-11-27 4:06:02]
# 1
Issue has been resolved. It was a set-up thing... Thank you for your time and patience!
CathyGrega at 2007-7-12 9:11:03 > top of Java-index,Core,Monitoring & Management...
# 2

Hi Cathy (or Greg?),

If you want to access the JVM Management & Monitoring MBeans (the MBeans

in the java.lang: domain) then it would be more robust to use

ManagementFactory.getPlatformMBeanServer();

rather than

MBeanServerFactory.findMBeanServers(null).get(0);

The platform MBeanServer is usually the first element in the list returned

by MBeanServerFactory.findMBeanServers(), but not necessarily...

Hope this helps,

-- daniel

JMX, SNMP, Java, etc...

http://blogs.sun.com/jmxetc

dfuchsa at 2007-7-12 9:11:03 > top of Java-index,Core,Monitoring & Management...