为什么在同一台机器上运行多个Java应用程序时,没有JMX冲突呢?

huangapple go评论77阅读模式
英文:

Why there is no JMX conflict even when more than one java application is running on the machine?

问题

Memory Analysers(仪器和监控工具)如VisualVM和jProfiler通过JMX扩展连接到Java应用程序的JVM(尽管可能还有其他连接方式,比如jstatd等,我见过JMX非常常见)。

我对JMX的理解:
默认情况下,JMX必须暴露其默认端口(不确定是否有默认端口号),以便内存分析工具可以连接。因此,我假设当有多个使用默认JMX配置的Java应用程序在同一台机器上运行时,必定会存在JMX端口冲突。

但我从未注意到这一点。我见过Java应用程序以默认配置运行,并且内存分析工具可以同时连接到这些Java应用程序中的每一个。所以我对JMX端口的理解并不完全正确。是否有人能解释一下为什么同一台机器上的多个Java应用程序如何能够在默认配置下同时暴露JMX功能(JMX是否为每个Java应用程序使用随机端口?)

英文:

Memory Analysers (Instrumentation and Monitoring tools) like VisualVM and jProfiler connect to Java Application's JVM though JMX extensions (though there might be other means to connect - like jstatd etc, i have seen JMX is quite common)

My Understanding About JMX:
By default JMX must expose its default port(not sure if there is a default port number) so that Memory Analysers can connect. So, I assume that when more than one java apps are running with default JMX config, on the same machine, there must be a JMX port conflict.

But I have never noticed that. I have seen java apps running happily with default configs and Mem Analysers could happily connect with each of these java apps at the same time. So my understanding about JMX ports is not entirely correct. Could some one say how more than one java app is able to expose JMX functionality with default configurations at the same time on the same machine. (???? is a random port used by JMX for each java application????)

答案1

得分: 1

工具如VisualVM与JMX动态附加机制一起使用,以监视本地Java虚拟机。

  1. 首先,该工具通过Attach API连接到本地JVM。
  2. 然后,它通过Attach API执行一个命令,在目标JVM中启动管理代理(JMX服务器)。
  3. 目标JVM在某个空闲端口上启动管理代理,并在代理属性中设置打开的端口值。
  4. 该工具再次使用Attach API来读取代理属性,从而发现代理监听的端口。
  5. 然后,它在此端口上建立与管理代理的JMX连接。

显然,不同的本地JVM在不同的端口上启动管理服务器,但VisualVM通过动态附加方式发现端口号。

英文:

Tools like VisualVM use JMX together with Dynamic Attach mechanism to monitor local Java Virtual Machines.

  1. First, the tool connects to a local JVM via Attach
    API
    .
  2. Then it executes (also via Attach API) a command to start Management Agent (JMX server) in the target JVM.
  3. The target JVM starts Management Agent on some free port and sets the opened port value in the Agent properties.
  4. The tool uses Attach API again to read Agent properties, and thus discovers the port the Agent listens to.
  5. Then it establishes the JMX connection to the Management Agent on this port.

Obviously, different local JVMs start Management Server on different ports, but VisualVM discovers the port number via Dynamic Attach.

huangapple
  • 本文由 发表于 2020年9月4日 02:39:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/63729805.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定