当前位置:网站首页>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 !
边栏推荐
- 干单片机这一行的时候根本没想过这么多,只想着先挣钱养活自己
- Qt QComboBox QSS样式设置
- Common software open source protocols
- Solve the problem of disordered code in vscode development, output Chinese and open source code
- [csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
- Patent inquiry website
- PRACH --- originator
- STM32 port multiplexing and remapping
- Leetcode daily question (516. long palindromic subsequence)
- 1922. Count Good Numbers
猜你喜欢

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)

Mysql database underlying foundation column

Nr-prach: access scenario and access process

MySQL environment variable configuration

Flink learning notes (XI) table API and SQL

UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)

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

Leetcode daily question (2090. K radius subarray averages)

Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit

Analysis of the implementation principle of an open source markdown to rich text editor
随机推荐
Intelligent home design and development
[CSDN] C1 training problem analysis_ Part III_ JS Foundation
Leetcode daily question (2212. maximum points in an archery competition)
Runtime. getRuntime(). GC () and runtime getRuntime(). The difference between runfinalization()
[graduation successful] [1] - tour [Student Management Information System]
Call the contents of Excel cells opened at the same time - button line feed
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
JMX、MBean、MXBean、MBeanServer 入门
Idea remote breakpoint debugging jar package project
2021-09-26
【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
[CSDN] C1 training problem analysis_ Part II_ Web Foundation
Project scope management__ Scope management plan and scope specification
Electronic product design, MCU development, circuit cloning
Code word in NR
Leetcode daily question (745. prefix and suffix search)
Nr--- Pusch I: sorting out the agreement process
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
Convert IP address to int