当前位置:网站首页>Getting started with JMX, MBean, mxbean, mbeanserver
Getting started with JMX, MBean, mxbean, mbeanserver
2022-07-03 09:48:00 【Enter the sky with one hand】
List of articles
One 、 Concept
1.JMX
Baidu Encyclopedia's explanation is :
JMX(Java Management Extensions, namely Java Manage extensions ) Is an application for 、 equipment 、 System and other embedded management function framework .JMX It can span a series of heterogeneous operating system platforms 、 System architecture and network transmission protocol , Flexible development of seamless integrated systems 、 Network and service management applications .
Popular point theory :
JMX It's a JDK The framework provided , Used to manage detection Java Program , Provide for the right to Java Applications and JVM Monitoring and management functions .
JMX adopt MBean、MXBean、MBeanServer To achieve the right java Procedure management
2.MBean
MBean It's a normative JavaBean, It integrates and implements a set of standard Bean Interface , such bean It's called MBean,Mbean Need to register to MBeanServer Managed in .
Usage specification : You need to define a name that ends with MBean The interface of , for example : Create a StudentMBean Interface , Then the name of the implementation class of this interface must be Student, At this time Student Of bean Namely MBean.
3.MXBean
MXBean yes MBean Generalized variant of ,MXBean And MBean The main difference is that some custom types of classes will be referenced in the interface ( Non native types ,int、String etc. ), When JMX Use this MXBean when , This custom type class will be converted to a standard type ,CompositeDataSupport class .
Usage specification : It and MBean The usage specification of is the same , Only the name of the interface ends with MXBean
It should be noted that : If your MXBean I have defined the constructor with parameters ( The nonparametric structure is covered ), Will report a mistake :
Do not know how to make a JavaFTP.Book from a CompositeData: no method from(CompositeData); no constructor has @ConstructorProperties annotation; does not have a public no-arg constructor; not an interface
The solution is : Manually add a parameterless constructor
4.MBeanServer
MBeanServer yes JMX The core manager of the agent layer , all MBean All need to MBeanServer register , All right MBean All operations are passed MBeanServer To perform the .
stay MBeanServer in , every last MBean There is a unique sign ObjectName Bind to it .
Two 、 Code example
1.MBean
Define a MBean Interface
public interface StudentMBean {
public int getAge();
public String getName();
public String getEmail();
public void setEmail(String email);
public String sayHello();
}
Implementation class , That is to say MBean
public class Student implements StudentMBean {
private final int age;
private final String name;
private String email;
public Student(int age, String name, String email) {
this.age = age;
this.name = name;
this.email = email;
}
@Override
public int getAge() {
return age;
}
@Override
public String getName() {
return name;
}
@Override
public String getEmail() {
return email;
}
@Override
public void setEmail(String email) {
this.email = email;
}
@Override
public String sayHello() {
return "hello " + name;
}
}
Test class :
public class MBeanServerTest {
public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, InterruptedException {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName student_objectName = new ObjectName("com.liqiye.jmx.mbean:type=Student");
Student student = new Student(26,"liqiye","[email protected]");
mBeanServer.registerMBean(student, student_objectName);
Thread.sleep(Long.MAX_VALUE);
}
}
function main After the method , Open you up JDK Of /bin Catalog Under the jconsole.exe
You can see that there is java When the program is executed JDK Built in MBean, And what we just defined Student This MBean
2.MXBean
Define a MXBean Interface
public interface TeacherMXBean {
public int getAge();
public String getName();
public String getEmail();
public void setEmail(String email);
public String sayHello();
public List<Book> getBook();
public void addBook(Book book);
}
Implementation class , That is to say MXBean
public class Teacher implements TeacherMXBean {
private final int age;
private final String name;
private String email;
private List<Book> books;
public Teacher(int age, String name, String email) {
this.age = age;
this.name = name;
this.email = email;
this.books = new ArrayList<>();
}
@Override
public int getAge() {
return age;
}
@Override
public String getName() {
return name;
}
@Override
public String getEmail() {
return email;
}
@Override
public void setEmail(String email) {
this.email = email;
}
@Override
public String sayHello() {
return "hello " + name;
}
@Override
public List<Book> getBook() {
return books;
}
@Override
public void addBook(Book book) {
books.add(book);
}
}
Test class :
public class MBeanServerTest {
public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, InterruptedException {
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName("com.liqiye.jmx.mbean:type=Student");
ObjectName teacher_objectName = new ObjectName("com.liqiye.jmx.mxbean:type=Teacher");
Book book = new Book("java book ", 30L);
Teacher teacher = new Teacher(27, " Xiao Qi ", "11");
teacher.addBook(book);
mBeanServer.registerMBean(teacher, teacher_objectName);
Thread.sleep(Long.MAX_VALUE);
}
}
jconsole Can be seen in MXBean There is Book The properties of this custom class , And can get the value inside
summary
Welcome to point out my mistake !
边栏推荐
- Solve the problem of disordered code in vscode development, output Chinese and open source code
- Vector processor 9_ Basic multilevel interconnection network
- IDEA远程断点调试jar包项目
- Definition and use of enum in C language
- UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
- UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
- Equality judgment of long type
- Fundamentals of Electronic Technology (III)__ Fundamentals of circuit analysis__ Basic amplifier operating principle
- 编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
猜你喜欢
What do software test engineers do? Pass the technology to test whether there are loopholes in the software program
Leetcode daily question (2212. maximum points in an archery competition)
【順利畢業】[1]-遊覽 [學生管理信息系統]
PolyWorks script development learning notes (I) - script development environment
Nr--- Pusch I: sorting out the agreement process
Flink learning notes (XI) table API and SQL
端午节快乐!—— canvas写的粽子~~~~~
【男保姆式】教你打开第一个微信小程序
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
嵌入式系统没有特别明确的定义
随机推荐
Patent inquiry website
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
MYSQL数据库底层基础专栏
How does the nr-prach receiver detect the relationship between prembleid and Ta
[CSDN]C1訓練題解析_第三部分_JS基礎
IDEA远程断点调试jar包项目
【顺利毕业】[1]-游览 [学生管理信息系统]
Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~
顺利毕业[3]-博客系统 更新中。。。
SSB Introduction (PbCH and DMRs need to be supplemented)
Make the most basic root file system of Jetson nano and mount NFS file system on the server
Project scope management__ Scope management plan and scope specification
Jestson nano downloads updated kernel and DTB from TFTP server
QT qstring:: number apply base conversion
C language enumeration type
NR technology -- MIMO
Project cost management__ Cost management technology__ Article 6 prediction
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
Qt QComboBox QSS样式设置