[英]How to monitor a Java program using Jconsole?
I have written a program to print number from 1 to 200 using 2 threads. 我编写了一个程序,使用2个线程打印1到200的数字。
Now I want to monitor this program using JConsole. 现在我想使用JConsole监视这个程序。
Basically I want to learn how to use JConsole for monitoring an application. 基本上我想学习如何使用JConsole来监视应用程序。
I searched google but couldn't find something useful. 我搜索谷歌但找不到有用的东西。
How I can achieve this? 我怎么能做到这一点?
When I started jconsole.exe
in bin folder. 当我在bin文件夹中启动
jconsole.exe
时。 It asks for hostname and port number. 它要求输入主机名和端口号。 Here in my case, there is none, I guess.
在我的情况下,我猜没有。 Can somebody guide.
有人可以指导。
Let's say you have a class Test
under package p1
where you have the code to print numbers from 1 to 200 using 2 threads(which you want to monitor). 假设你在包
p1
下有一个类Test
,你可以使用2个线程(你想要监视的)打印1到200的数字。
So to use jconsole for monitoring your application, you would need to compile and execute your code first and while your code is executing... 因此,要使用jconsole监视应用程序,您需要首先编译并执行代码,同时执行代码...
Start
-> Run
-> jconsole.exe
and hit/press Enter
Start
- > Run
- > jconsole.exe
然后单击/按Enter
Select the application which you want to monitor and then click Connect
. 选择要监视的应用程序,然后单击“
Connect
。
Alternatively,you can use VisualVM for this purpose as well. 或者,您也可以将VisualVM用于此目的。
You need to enable JMX
by adding the following JVM
arguments : 您需要通过添加以下
JVM
参数来启用JMX
:
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8484
-Dcom.sun.management.jmxremote.ssl=false
These parameters will allow any JMX
monitoring tool to access and monitoring your application. 这些参数将允许任何
JMX
监视工具访问和监视您的应用程序。
Also i suggest you to use visualVM
its more powerful tool. 另外我建议你使用
visualVM
这个更强大的工具。 some features for visualVM
: visualVM
一些功能:
JConsole find all the running application at the time of JConsole start-up. JConsole在JConsole启动时查找所有正在运行的应用程序。 Then only the currently running applications port and host will be displayed in the list.
然后,只有当前运行的应用程序端口和主机才会显示在列表中。 So first you need to start the application then start the JConsole.
首先,您需要启动应用程序然后启动JConsole。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.