Use createMBean( ) to Create MBeans
One of the purposes of the MBean server is to act as a communications bus for interacting with MBeans. You should never manipulate an MBean through a direct object reference, for several reasons:
Only registered MBeans can be manipulated via the MBean server. Part of the registration process is an introspection of the MBean to ensure that it conforms to the requirements of the JMX specification. Only compliant MBeans should be considered manageable.
Only agents in the same process as an MBean can manipulate it through an object reference. This presupposes knowledge of the deployment of the MBean relative to the agent and should be avoided to minimize maintenance issues.
Java Specification Request (JSR) 160, or JMX 1.2 Remoting, specifies security requirements for JMX implementations.[21] Direct manipulations of an MBean through an object reference are not subject to JMX security checks and should be avoided.
In the same vein, creating MBeans via the Java
newkeyword should also be avoided. TheMBeanServerinterface implemented by the MBean server provides a method (instantiate( )) to create instances of MBeans, which return a reference to the newly created MBean object. To register an existing MBean, the agent callsregisterMBean( ). TheMBeanServerinterface also provides a method calledcreateMBean( )that combines these two steps, but never exposes a reference to the MBean object outside the JMX implementation.
[21] At the time of this ...