You
can use JMX to monitor and manage JVM. Let me explain with an example.
Test.java
package com.sample.app; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; public class Test { private static List<Integer> tempList = new ArrayList<> (); public static void main(String args[]) throws InterruptedException { while(true) { tempList = new ArrayList<> (); for(int i=0; i < 10000000; i++) { tempList.add(i); } TimeUnit.SECONDS.sleep(10); } } }
Run
Test.java.
Open
command prompt (or) terminal and execute the command jconsole.
Select
the process with name ‘com.sample.app.Test’ and click on Connect button.
If
you see below kind of window, click on ‘Insecure Connection’ button.
It
launches below window.
In
the overview section, you can able to see
a. Heap memory usage of
the application
b. Number of threads
c. Number of loaded
classes
d. CPU consumption usage
details
Go
to Memory tab, to see detailed report on Heap Memory usage.
If
you want to see complete summary of the memory, cpu and operating system
details, click on ‘VM Summary’ tab.
How to request for
garbage collection from jconsole?
Go
to Memory tab and click on ‘Perform GC’ button.
Before
click on ‘Perform GC’ button.
After
clicking ‘Perform GC’ button.
No comments:
Post a Comment