Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to monitor a Java program using Jconsole?

I have written a program to print number from 1 to 200 using 2 threads.

Now I want to monitor this program using JConsole.

Basically I want to learn how to use JConsole for monitoring an application.

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.

like image 960
Thinker Avatar asked Mar 09 '14 08:03

Thinker


3 Answers

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.
like image 62
Salah Avatar answered Oct 30 '22 20:10

Salah


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

    enter image description here

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

    enter image description here

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

  • enter image description here
like image 37
Sandeep Chatterjee Avatar answered Oct 30 '22 21:10

Sandeep Chatterjee


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.

like image 40
Sonu Avatar answered Oct 30 '22 19:10

Sonu