Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the application of JMX in Tomcat?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the application of JMX in Tomcat, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Let's talk about MBeanServer in Tomcat in detail.

1. JMX (Java Management Extensions)

When it comes to MBeanServer, we have to mention JMX. JMX is an interface specification for managing and monitoring JAVA applications. It also has the following characteristics:

Read data through the "MBeans" of JMX

Properties that can be read and written to MBean

Methods that can execute MBean

We are all familiar with reflection in JAVA, and the overall implementation and role of JMX is very similar to reflection. It's just that JMX allows the execution of target methods on the remote host.

Through JMX, you can easily get various data values of JVM, such as the number of GC executions, the type of GC currently used by JVM, memory footprint, time of GC pauses, and so on.

On top of this, Tomcat exposes a lot of useful data, such as the connection data of specific channels, the number of requests, the number of responses, the number of failed requests, thread pool data, JNDI data and so on.

In JMX, there are three key concepts:

MBeanServer

ObjectName

MBean

Where MBeanServer represents the specific server to operate, similar to which website we are going to visit.

ObjectName represents the name of a specific object registered by MBeanServer, just like the name of a particular page on a website. The subsequent property acquisition and method execution all get the MBean object after specifying a specific ObjectName, and then execute its specific properties and methods.

As shown in the figure above, after connecting to the MBeanServer of Tomcat, you can see the tree-shaped MBeans on the left. The red box represents the commonly used 8080-channel MBean, and its corresponding ObjectName is Catalina:type=Connector,port=8080.

Inside Tomcat, during startup, a lot of core data will be registered to MBeanServer through MBean, which is convenient for monitoring and management.

Now that we understand the basic concepts, let's take a look at the examples mentioned in the previous article to specifically look at the role of JMX in Tomcat.

Start Tomcat and use the jps command to get its corresponding PID

Using jconsole, connect to the MBeanServer corresponding to that Tomcat.

Check what the ObjectName corresponding to the MBeanServer has, and select the specific object to be operated on.

Because of the stack call of Intellij IDEA when starting the deployment of Tomcat applications, we can know that the corresponding class of the ObjectName it calls is MBeanFactory.

TCP Connection (2)-127.0.0.1 / 1379 daemon, prio=5, in group 'RMI Runtime', status:' RUNNING'

At org.springframework.web.context.ContextLoaderListener. (ContextLoaderListener.java:98)

At org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:150)

At org.apache.catalina.core.ContainerBase.addChildInternal (ContainerBase.java:725)

At org.apache.catalina.core.ContainerBase.addChild (ContainerBase.java:701)

At org.apache.catalina.core.StandardHost.addChild (StandardHost.java:717)

At org.apache.catalina.startup.HostConfig.manageApp (HostConfig.java:1585)

At org.apache.catalina.mbeans.MBeanFactory.createStandardContext (MBeanFactory.java:463)

At org.apache.catalina.mbeans.MBeanFactory.createStandardContext (MBeanFactory.java:413)

At sun.reflect.NativeMethodAccessorImpl.invoke0 (NativeMethodAccessorImpl.java:-1)

At javax.management.remote.rmi.RMIConnectionImpl.doOperation (RMIConnectionImpl.java:1466)

At java.lang.Thread.run (Thread.java:745)

So

View the corresponding MBean of this class

Then take a look at the method named createStandContext for the MBean of the IDEA operation, as shown in the following figure. This method requires three parameters of type String, which is basically the same as configuring the Context element directly in server.xml.

After the above analysis, we already understand the core principles of IDEA internal Tomcat application deployment. And learned about JMX by the way. Later articles have the opportunity to talk about its use in specific projects.

The above is what the application of JMX in Tomcat is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report