JMX is slightly different on J2SE5 and J2SE6 platforms. We learn JMX Based on J2SE6. JMX is part of the successful Java2 Platform. Its goal is to dynamically manage and monitor resources you are interested in, such as applications, devices, services, and JVMs. JMX supports local and remote access to manage and monitor related resources. JMX only
JMX is slightly different on J2SE 5 and J2SE 6 platforms. We learn JMX Based on J2SE 6. JMX is already part of the successful Java 2 platform. Its goal is to dynamically manage and monitor resources you are interested in, such as applications, devices, services, and JVMs. JMX supports local and remote access to manage and monitor related resources. JMX is only an extension of application management, not a mandatory one. What are the benefits if we choose to implement the JMX management function for the system?
1. managing existing Java applications based on JMX can be easily implemented based on Java technology without additional investment;
2. JMX defines a specification and a set of standard APIs. The industry has incorporated JMX technology into its own products, such as JBoss and Weblogic;
Third, JMX has a set of standardsArchitectureMakes management dynamic, flexible, scalable, and stable;
Fourth, JMX can be easily integrated with other management solutions, such as accessing the proxy Server (MBean Server) through a browser ).
Next, let's take a look at the technical architecture of JMX, which can be divided into three layers:
1. device layer
This layer defines the resources to be managed, such as applications, devices, services, and networks. These resources are exposed as Java objects in MBean mode, such as standard MBean, define management interfaces with names containing MBean suffixes to associate these interfaces with the resources to be managed, and then register these Java objects to the proxy Server (MBean Server) to achieve remote management and monitoring.
For example, we have defined a standard MBean Management Interface (for other mbeans, refer to the relevant documentation ):
- PackageOrg. shirdrn. java. jmx. standardmbean;
- Public InterfaceMyObjectMBean {
- Public LongGetId ();
- PublicSTrIng getName ();
- Public VoId SetName (String name );
- PublicString show ();
- }
MBean implementation example is as follows:
- PackageOrg. shirdrn. java. jmx. standardmbean;
- ImportOrg. apache. log4j. Logger;
- Public ClassMyObjectImplementsMyObjectMBean {
- Private StatIc FinalLogger LOG = Logger. getLogger (MyObject.Class);
- Private LongId;
- PrivateString name;
- PublicMyObject (){
- SuPer();
- }
- PublicMyObject (LongId, String name ){
- Super();
- This. Id = id;
- This. Name = name;
- }
- Public LongGetId (){
- ReturnId;
- }
- Public VoidSetId (LongId ){
- This. Id = id;
- }
- PublicString getName (){
- ReturnName;
- }
- Public VoidSetName (String name ){
- This. Name = name;
- }
- PublicString show (){
- StringBuffer sb =NewStringBuffer (). append (\ "Id = \"). Append (id). append (\ ", Name = \")
- . Append (name );
- LOG.info (\ "Show () = \"+ Sb. toString ());
- ReturnSb. toString ();
- }
- }
As you can see, the management interface exposes four methods. You can view but cannot modify the id. You can view and modify the name and call the show method.
Note that for standard mbeans, if the MBean management interface is defined as xxxMBean, the implementation must be xxx. Otherwise, the corresponding resources cannot be found through the MBean Server.
2. Proxy Layer
The proxy layer provides a container for objects to be managed (such as Java objects that implement standard MBean management interfaces). Only objects that meet the requirements and are registered in the container can implement JMX management. The main component of the proxy layer is MBean Server, which acts as a proxy for management in our application system.