This discussion is archived
2 Replies Latest reply: Feb 4, 2010 9:19 AM by 843798 RSS

difference betwen ManagementFactory.getPlatformMBeanServer() and MBeanServe

800573 Newbie
Currently Being Moderated
please help me to know when we should use ManagementFactory.getPlatformMBeanServer() and when useMBeanServerFactory.createMBeanServer
  • 1. Re: difference betwen ManagementFactory.getPlatformMBeanServer() and MBeanServe
    843798 Newbie
    Currently Being Moderated
    The platform MBean Server can be shared by different managed components running within the
    same Java VM.
  • 2. Re: difference betwen ManagementFactory.getPlatformMBeanServer() and MBeanServe
    843798 Newbie
    Currently Being Moderated
    Hi.
    There is an interesting thing on this subject that I could not explain to myself until I read more carefully
    http://java.sun.com/javase/6/docs/api/java/lang/management/ManagementFactory.html#getPlatformMBeanServer().

    Just look to this code fragment:

    ArrayList<MBeanServer>       mbsn =     MBeanServerFactory.findMBeanServer(null);
    System.out.println(mbsn.isEmpty()" "+mbsn.size());+
    MBeanServer                        mbs =     ManagementFactory.getPlatformMBeanServer();
    mbsn =     MBeanServerFactory.findMBeanServer(null);
    System.out.println(mbsn.isEmpty()" "+mbsn.size()+" "+mbs);+

    and to its output:

    true 0
    false 1  com.sun.jmx.mbeanserver.JmxMBeanServer@a39137

    The reason is that when I ran this piece of code the platform MBean server had not yet been started.
    Starting it - and how - is under direct or indirect user control.

    regards

    Edited by: mrsunnts on Feb 4, 2010 5:15 PM