如何使用 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:43:04  来源:igfitidea点击:

How to monitor a Java program using Jconsole?

javamultithreadingjconsole

提问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.exein 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 JMXby adding the following JVMarguments :

您需要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 JMXmonitoring tool to access and monitoring your application.

这些参数将允许任何JMX监控工具访问和监控您的应用程序。

Also i suggest you to use visualVMits 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 Testunder package p1where 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.exeand hit/press Enter

    enter image description here

  • Select the application which you want to monitor and then click Connect.

    enter image description here

  • Start-> Run->jconsole.exe并点击/按下Enter

    在此处输入图片说明

  • 选择要监控的应用程序,然后单击Connect

    在此处输入图片说明

Alternatively,you can use VisualVMfor this purpose as well.

或者,您也可以为此目的使用VisualVM

  • enter image description here
  • 在此处输入图片说明

回答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。