Get Thread and Heap dump – Java

 

Thread and Heap dumps are useful for debugging any Java programme.

To get thread dump:

By using jstack command we can get thread dump of a Java process.

Example:

$ jstack PID

where PID is Java process id for which we want to get thread dump.

To get heap dump:

By using jmap command we can get heap dump of a Java process.

Exmaple:

$ jmap -heap PID

where PID is Java process id for which we want to get heap dump.

Advertisements

java string replace multiple occurrences of a character

 

To replace multiple occurrences of a character in a string use following regular expression in your java code:

String s = "helloooooo";
s = s.replaceAll("(.)\\1+","$1");
System.out.println(s);

In above code input string helloooooo is converted as hello

Output:

hello

By Sandeep Posted in Java Tagged