Pages

January 8, 2014

Java memory analysis using inbuilt tools

jhat(Heap Analysis Tool) is a tool that comes along with the jdk and is present under jdkxxx/bin/ .

There are two way to get the heap dump

1. Give it while starting the java program as
java -Xrunhprof:format=b,file=file.hprof class-name
2. Get the heap dump using jmap as
jmap -dump:file=file-name process_id

Here I am using the first method. The java code ran is the same as described in this post about Thread-Creation-Time.

January 1, 2014

Java analyzing thread creation time

In Java, the thread creation time increases with the number of thread that are already created, hence it is advisable to keep the thread count minimal and only create a Thread when actually needed.

The below gist is a minimal piece of java code that helps in proving this