Some good resources/tutorials:
https://www.youtube.com/watch?v=iixQAYnBnJw https://www.toptal.com/java/hunting-memory-leaks-in-java I'm not going to talk too much about what it is, it's all here: https://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html This post is primarily to learn how to use it. Start off with a Java program that runs indefinitely and creates objects. import java.time.Instant; class Jmap{ String name; public Jmap(String name) { this.name = name; System.out.println("New Object with name " + name + " created"); } @Override public void finalize() { System.out.println("Obkect with name " + name + " destroyed"); } @Override public String toString() { return this.name; } } public class JMapTutorial { public static void main(String[] args) { Jmap j; while(true) { try { Thread.sleep(10000); j = new Jmap(Instant.now().toString()); } catch (InterruptedException e) { //e.printStackTrace(); } } } }
Find the Java process running using command:
ps -ef | grep java look for what you want to monitor, in this case I had (the PID I need is in red): 501 90817 555 0 12:31PM ?? 0:00.33 /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java -Dfile.encoding=UTF-8 -classpath /Users/gulanurmatova/eclipse-workspace/bin JMapTutorial Run the JCONSOLE: $ jconsole 90817 Output of the program run below and the screenshot of the Jconsole - everything makes sense so far - create, create, create, bunch of clean-ups and then again create, create, create. Let's see what happens next...
0 Comments
Leave a Reply. |
This is a collection of interview prep programs, online resources that were used in my Java classes. The Java classes were taught years ago, hence the material is likely outdated, I will make an effort to go through it and update as time permits Categories |