JMX= JAVA Management Extension
Name itself suggest it is extension provided by JAVA for managing
JAVA Application/System my monitoring application
performance problem, some critical events like quick increase in network
traffic and decrease in application performance. With using JMX we can notify
the developer about such behavior of the application using JMX console. In JDk
8 you can refer to this command in bin folder of java i.e. jmc.
Lets try to learn basics of JMX and learn how to use JConsole
to connect and manage MBeans.
Step 1- Create MBean. It should be interface in nature. The
interface name must end with MBean.
package com.test.siddhu;
public interface SiddhuMBean {
public void setMyCount(int myCount);
public int getMyCount();
public void setMyName(String schemaName);
public String getMyName();
//
Method started with get and set are considered as attributes for getter and
setter methods
//
We are using do* for perform action.
public String doAction();
}
Step 2- Provide the actual implementation of the MBean
interface. As per the standard of JMX Naming convention we need to keep implementation
class name as same of interface except– MBean. So my implementation class will
be Siddhu.
package com.test.siddhu;
public class Siddhu implements SiddhuMBean {
private int myCount;
private String myName;
@Override
public void setMyCount(int myCount) {
// TODO Auto-generated
method stub
this.myCount=myCount;
}
@Override
public int getMyCount() {
// TODO Auto-generated
method stub
return this.myCount;
}
@Override
public void setMyName(String myName) {
// TODO Auto-generated
method stub
this.myName=myName;
}
@Override
public String getMyName() {
// TODO Auto-generated
method stub
return this.myName;
}
@Override
public String doAction() {
// TODO Auto-generated
method stub
return "My Count="+this.myCount+" and My Name="+this.myName;
}
}
Step 3- Now register our MBean implementation to the MBean
server. We are using SiddhuActionManagement class for this. After registering
MBean,To check our application is on we will print out mycount and myName value
frequently. But same operation we will stop once we declare out myCount value
as 0.
Click on Jconsole in bin folder of JAVA
Change value from 1 to 0 and we will see our application get
stop.
If we change the name in the jconsole we found at run time
with out changing the java class out put is changed
No comments:
Post a Comment