如何使用 Jconsole 监控 Java 程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22280229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to monitor a Java program using Jconsole?
提问by Thinker
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. It asks for hostname and port number.
Here in my case, there is none, I guess.
Can somebody guide.
当我jconsole.exe
在 bin 文件夹中开始时。它要求提供主机名和端口号。就我而言,我想没有。有人可以指导。
采纳答案by Salah
You need to enable JMX
by adding the following JVM
arguments :
您需要JMX
通过添加以下JVM
参数来启用:
-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.
some features for visualVM
:
另外我建议你使用visualVM
它更强大的工具。一些功能visualVM
:
- Provide a CPU profiling.
- Provide all info about Threads.
- Provide the JVM Heap and the memory states.
- Provide Info about the GC activities.
- 提供 CPU 分析。
- 提供有关线程的所有信息。
- 提供 JVM 堆和内存状态。
- 提供有关 GC 活动的信息。
回答by Sandeep Chatterjee
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).
假设您Test
在包p1
下有一个类,您可以在其中使用 2 个线程(要监视的线程)打印从 1 到 200 的数字的代码。
So to use jconsolefor 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/pressEnter
Select the application which you want to monitor and then click
Connect
.
Start
->Run
->jconsole.exe
并点击/按下Enter
选择要监控的应用程序,然后单击
Connect
。
Alternatively,you can use VisualVMfor this purpose as well.
或者,您也可以为此目的使用VisualVM。
回答by Sonu
JConsole find all the running application at the time of JConsole start-up. 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 在 JConsole 启动时查找所有正在运行的应用程序。那么列表中将只显示当前运行的应用程序端口和主机。所以首先您需要启动应用程序,然后启动 JConsole。