当前位置:网站首页>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 !
边栏推荐
- 嵌入式系统没有特别明确的定义
- How MySQL modifies null to not null
- Flink learning notes (10) Flink fault tolerance mechanism
- Find all possible recipes from given supplies
- numpy. Reshape() and resize() functions
- How does the memory database give full play to the advantages of memory?
- STM32 port multiplexing and remapping
- Leetcode daily question (2232. minimize result by addressing parents to expression)
- 1922. Count Good Numbers
- Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
猜你喜欢

內存數據庫究竟是如何發揮內存優勢的?
![[CSDN] C1 training problem analysis_ Part II_ Web Foundation](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。

Electronic product design, MCU development, circuit cloning

How does the nr-prach receiver detect the relationship between prembleid and Ta

Idea remote breakpoint debugging jar package project

Leetcode daily question (2212. maximum points in an archery competition)

Solve editor MD uploads pictures and cannot get the picture address

Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~

Leetcode daily question (1162. as far from land as possible)
随机推荐
Win10 install elk
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
MySQL 数据库基础知识(系统化一篇入门)
Development of electrical fire system
Electronic product design, MCU development, circuit cloning
Electronic product design
You need to use MySQL in the opening experiment. How can you forget the basic select statement? Remedy is coming~
Intelligent home design and development
Introduction to chromium embedded framework (CEF)
307. Range Sum Query - Mutable
Leetcode daily question (516. long palindromic subsequence)
Flink CDC practice (including practical steps and screenshots)
Leetcode daily question (2232. minimize result by addressing parents to expression)
MySQL environment variable configuration
Matlab reads hexadecimal numbers and converts them into signed short
Vscode Arduino installation Library
Error output redirection
2021-09-26
Leetcode daily question (968. binary tree cameras)
Oracle数据库 SQL语句执行计划、语句跟踪与优化实例