kill -3 java_pid命令將輸出java進(jìn)程的線程信息。
在AIX上在域的目錄下生成javacore文件
在linux上,信息將輸出到console
對(duì)于thread dump信息,主要關(guān)注的是線程的狀態(tài)和其執(zhí)行堆棧
線程的狀態(tài)一般為三類
Runnable(R):當(dāng)前可以運(yùn)行的線程
Waiting on monitor(CW):線程主動(dòng)wait
Waiting for monitor entry(MW):線程等鎖
一般關(guān)注的都是第一和第三種狀態(tài)的線程
Cpu很忙則關(guān)注runnable的線程
Cpu閑則關(guān)注waiting for monitor entry的線程
狀態(tài)參考:
R - Running or runnable thread
S - Suspended thread
CW- Thread waiting on a condition variable(it is in a Thread.sleep or in a synchronized wait.)
MW - Thread waiting on a monitor lock(等待一個(gè)線程鎖)
MS - Thread suspended waiting on a monitor lock(there is a good chance it is a bug. )
Monitors are used to manage access to code that should only be run by a single thread at a time. A monitor can be thought of as a lock on an object, and every object has a monitor. (Monitor其實(shí)就是對(duì)象上面的鎖,提供多線程使用一個(gè)對(duì)象的機(jī)制)
Monitor類型:
utf8 hash table -Locks the hashtable of defined i18N Strings that were loaded from the class constant pool.
JNI pinning lock- Protects block copies of arrays to native method code.
JNI global reference lock -Locks the global reference table which holds values that need to be explicitly freed, and will outlive the lifetime of the native method call.
BinClass lock- Locks access to the loaded and resolved classes list. The global table list of classes
Class linking lock- Protects a classes data when loading native libraries to resolve symbolic references
System class loader lock- Ensures that only one thread is loading a system class at a time.
Code rewrite lock -Protects code when an optimization is attempted.
Heap lock- Protects the Java heap during heap memory management
Monitor cache lock -Only one thread can have access to the monitor cache at a time this lock ensures the integrity of the monitor cache
Dynamic loading lock- Protects Unix green threads JVMs from loading the shared library stub libdl.so more than once at a time.
Monitor IO lock -Protects physical I/O for example, open and read.
User signal monitor- Controls access to the signal handler if a user signal USRSIG in green threads JVMs.
Child death monitor -Controls access to the process wait information when using the runtime system calls to run locals commands in a green threads JVM.
I/O Monitor -Controls access to the threads file descriptors for poll/select events
Alarm Monitor- Controls access to a clock handler used in green threads JVMs to handle timeouts
Thread queue lock -Protects the queue of active threads
Monitor registry -Only one thread can have access to the monitor registry at a time this lock ensures the integrity of that registry
Has finalization queue lock *- Protects the list of queue lock objects that have been garbage-collected, and deemed to need finalization. They are copied to the Finalize me queue
Finalize me queue lock * -Protects a list of objects that can be finalized at leisure
Name and type hash table lock * -Protects the JVM hash tables of constants and their types
String intern lock * -Locks the hashtable of defined Strings that were loaded from the class constant pool
Class loading lock * -Ensures only one thread loads a class at a time
Java stack lock * -Protects the free stack segments list
linux上查看線程
用于 Linux 的 JVM 將 Java 線程作為本地線程實(shí)現(xiàn),這使每個(gè)線程成為一個(gè)獨(dú)立的 Linux 進(jìn)程。
使用top找出消耗cpu最多的進(jìn)程ID,把它轉(zhuǎn)換為16進(jìn)制數(shù)據(jù),再threaddump文件中找nid=0X2234E的線程,看它再做什么事情。
AIX上查看java進(jìn)程下所有線程的信息:
輸出線程ID
ps -mp 241888 -o THREAD
USER PID PPID TID ST CP PRI SC WCHAN F TT BND COMMAND
weblogic 241888 372868 - A 0 68 76 * 242001 - - /usr/java14/bin/java -Xms1024m -Xmx1024m -Dweblogic.Na
- - - 663693 Z 0 68 1 - c00001 - - -
- - - 671855 S 0 68 1 f100070f1000a440 8410400 - - -
- - - 753805 S 0 68 1 f100070f1000b840 8410400 - - -
- - - 766023 S 0 68 1 f10001001fe6aeb0 410400 - - -
- - - 774329 S 0 68 1 f100070f1000bd40 8410400 - - -
- - - 790667 S 0 68 1 f100070f1000c140 8410400 - - -
- - - 794635 S 0 68 1 f100070f1000c240 8410400 - - -
- - - 798813 S 0 68 1 f100070f1000c340 8410400 - - -
- - - 803021 Z 0 68 1 - c00001 - - -
- - - 807051 S 0 68 1 f100070f1000c540 8410400 - - -
- - - 811149 S 0 68 1 f100070f1000c640 8410400 - - -