JMX Usage

holdorph's blog is very good! link: http://www.unicon.net/node/614

About JMX

Actually, if you go to C:\COMET-DEV\workspaces\COES\config\quantum\cash\AP\dev\cash_coes_sls1, which is the config folder for COES, you can see that, there is actually one quantum config file --- spring-qas.xml, but go inside, you will find that, this file is composed of several sub config files. One of them is spr-include-mbeans.xml. And this file is just config the JMX as above.

 

How to config it

1)       Config a MBean Server "java.lang.management.ManagementFactory"

2)       Config a JMX exporter "org.springframework.jmx.export.MBeanExporter"

3)       Put all your POJOs into the exporter map.

4)       There is a requirement on how to write the key of the entry. You must follow the way of

 

<JMX category Name>:name=<MBean name>.

 

            In the below example, I config the

JMX category name = tom

MBean name = myNumber

 

5)       Also don’t forget to config your POJO.

 

An example

 

POJO

package test;

 

public class NumberHolder

{

      private int number = 100;

 

      public int getNumber()

      {

            return number;

      }

 

      public void setNumber(int number)

      {

            this.number = number;

      }

}

 

Spring

 

      <bean id="mbeanServer" class="java.lang.management.ManagementFactory"

            factory-method="getPlatformMBeanServer" />     

 

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">

            <property name="autodetect" value="true" />

            <property name="server" ref="mbeanServer" />

            <property name="beans">

                  <map>

                        <entry key="tom:name=myNumber" value-ref="number.holder" />

                  </map>

            </property>

      </bean>

     

<bean name="number.holder" class="test.NumberHolder"/>

 

 

How to Use it

2 requirements

 

1) Enable your JMX management function.  Simply add the following parameters in your java command.

-Dcom.sun.management.jmxremote

-Dcom.sun.management.jmxremote.port=9054

-Dcom.sun.management.jmxremote.authenticate=false

-Dcom.sun.management.jmxremote.ssl=false     

 

2) Use JConsole to connect to it.

            Jconsole.exe locates in the jdk/bin folder. You can add it as a eclipse external tool. When it is started, go to Remote tab, input host --- localhost   port --- 9054 as configged above. Connect

 

 

 

 

You can see a new category --- tom, and a new MBean --- myNumber. Then, you can invoke the MBean public method.

 

 

 

你可能感兴趣的:(eclipse,spring,bean,sun,Comet)