Skip to content
William Zhang edited this page Dec 16, 2016 · 11 revisions

JDK

How to print the JVM settings?

$ java -XshowSettings:properties -version

hprof

http://docs.oracle.com/javase/7/docs/technotes/samples/hprof.html

jstack

http://flysnowxf.iteye.com/blog/1162691

  1. top or ps -ef to find the pid
  2. top -p <pid>, then shift+h to show threads, and find the interesting tid
  3. jstack <pid> | grep -A 10 <tid>

jstat, jmap, jdb, jps, jinfo etc.

http://ju.outofmemory.cn/entry/147496

http://www.cnblogs.com/yyyt/p/4307828.html

http://docs.oracle.com/javase/6/docs/technotes/tools/share/jstat.html

Memory usage

$ jmap -histo:live 20627

Memory usage and GC times/timestamp. Where 1000 means 1ms, 5 means 5 times.

$ jstat -gcutil 20627 1000 5

Eclipse

Disable code formattor

//
// @formatter:off
// Comments
// @formatter:on
//

Enable assertion

Windows -> Preferences -> Java -> Installed JREs -> Edit -> Default VM arguments:

-ea
-XX:+CreateMinidumpOnCrash

WinDBG (hide it here):

srv*D:\SymbolCache*https://msdl.microsoft.com/download/symbols

Java language

How to print the backtrace?

for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
    System.out.println(ste);
}

Why use `b & 0xFF` in bitwise operators?

Bitwise operators in Java is not the same as that in C/C++. Read this great article for details.

Also see long & 0xFFFFFFFF vs. long & 0xFFFFFFFFL.

log4j

  1. 1.x to 1.2 migrate link.
  2. 1.2 sample with Maven link.
Clone this wiki locally