====== Java ThreadDump ====== * [[java:jcmd|jcmd]] * [[https://docs.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html|jstack]] * [[http://fastthread.io/|FastThread.io]] Online Fast Thread Dump * [[http://fasterj.com/tools/threadanalysers.shtml|FasterJ Thread Dump analyzer 링크 모음]] * [[https://github.com/irockel/tda|Thread Dump Analyzer]] * [[https://java.net/projects/tda/downloads/directory/visualvm|Thread Dump Analyzer VisualVM Plugin]] 세 파일을 다 받아서 설치해 줄 것. * [[https://spotify.github.io/threaddump-analyzer/|Online Java Threaddump analyzer]] - [[https://github.com/spotify/threaddump-analyzer|github source]] * [[https://www.ibm.com/developerworks/community/groups/service/html/communityview?communityUuid=2245aa39-fa5c-4475-b891-14c205f7333c|IBM Thread and Monitor Dump Analyzer for Java]] * [[http://www.pythian.com/blog/a-simple-way-to-monitor-java-in-linux/|A Simple Way to Monitor Java in Linux]] * [[http://code.nomad-labs.com/2010/11/18/identifying-which-java-thread-is-consuming-most-cpu/|Identifying which Java Thread is consuming most CPU]] * [[https://github.com/sparameswaran/threadlogic|ThreadLogic]] : 아직까지 보기엔 제일 나은 듯. 다중 쓰레드 덤프 못 읽는 문제 생긴 듯. ===== dump 뜨기 ===== # java process 확인 jps # jstack jstack # jcmd jcmd Thread.print # kill -3 : process system.out 으로 출력된다. kill -3 * ''kill -3''의 경우 다음 옵션을 주고 JVM을 띄웠다면 해당 파일(''~/jvm.log'')로 thread dump가 떠진다. -XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=~/jvm.log ===== waiting 하고 있는 monitor가 있는데 어느 쓰레드가 해당 monitor를 locking 하고 있는지 정보가 없는 상황 ===== * Thread Dump를 떴을 때 분명 ''wait for ''은 존재하는데 ''locked ''은 존재하지 않는 경우가 있음. * TDA 가 출력한 내용에 따르면, * a VM Thread is holding it. * This lock is a java.util.concurrent lock and the thread holding it is not reported in the stack tracebecause the JVM option -XX:+PrintConcurrentLocks is not present. * This lock is a custom java.util.concurrent lock either not based off of AbstractOwnableSynchronizer or not setting the exclusive owner when a lock is granted. * 일반적으로는 ''java.util.concurrent'' lock 인 경우로 보이며 JVM option **''-XX:+PrintConcurrentLocks''**로 JVM을 띄워야 명백히 lock을 잡은 쓰레드가 보임. ===== nid/tid ===== * tid : java가 스스로 붙이는 쓰레드 단위 ID * nid : Native ID. OS 차원의 쓰레드 ID, linux에서는 ''top -H''로 볼 때 PID라고 보임. * ''top''과 ''jstack'' 조합하기 : [[http://stackoverflow.com/questions/4764167/inspecting-java-threads-in-linux-using-top|Inspecting Java threads in Linux using top]] ===== 참조 ===== * [[http://helloworld.naver.com/helloworld/10963|스레드 덤프 분석하기]] [[http://architects.dzone.com/articles/how-analyze-java-thread-dumps|How to Analyze Java Thread Dumps | 영문번역판]] : 쓰레드 덤프에 대한 기초 상식을 다질 수 있는 매우 좋은 글이다. * [[http://www.java2s.com/Code/Java/Development-Class/ThisFullThreadDumpclassdemonstratesthecapabilitytogetafullthreaddumpandalsodetectdeadlockremotely.htm|This FullThreadDump class demonstrates the capability to get a full thread dump and also detect deadlock remotely.]] * [[http://www.javacodegeeks.com/2015/08/making-thread-dumps-intelligent.html|Making Thread Dumps Intelligent]] * [[http://openparadigm.tistory.com/m/post/30|자바 쓰레드에 대한 모든것!!..은 아니고;;(JAVA Thread)]] - Java Thread에 관한 간단한 정리 * [[https://dzone.com/articles/how-to-take-thread-dumps-7-options|7 Options for Capturing Thread Dumps]] * [[https://www.baeldung.com/java-analyze-thread-dumps|How to Analyze Java Thread Dumps]] * [[https://www.baeldung.com/java-thread-dump|Capturing a Java Thread Dump | Baeldung]]