How to monitor a Java program using Jconsole?

左心房为你撑大大i 提交于 2019-11-30 17:34:53
Salah

You need to enable JMX by adding the following JVM arguments :

-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.

Also i suggest you to use visualVM its more powerful tool. some features for visualVM:

  • Provide a CPU profiling.
  • Provide all info about Threads.
  • Provide the JVM Heap and the memory states.
  • Provide Info about the GC activities.

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).

So to use jconsole for monitoring your application, you would need to compile and execute your code first and while your code is executing...

  • Start -> Run -> jconsole.exe and hit/press Enter

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

Alternatively,you can use VisualVM for this purpose as well.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!