java 获取线程dump最佳方案

时间:2025-03-22 18:06:59
public class Runthread {
public static void main(String[] args) {


// 线程1
new Thread() {
@Override
public void run() {
("这是线程1的run1111111111");
}
}.start();


// 线程2
new Thread() {
@Override
public void run() {
try {
(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
();
}
("这是线程2的run222222222");
}
}.start();


ThreadMXBean b = ();
List<ThreadInfo> threadInfoList = Arrays
.asList(((), ()));
for (ThreadInfo info : threadInfoList) {
TThreadDump dump = new TThreadDump();


(());
(());
(());
(());
(());
(());


(());
(());
(());


(());
(());


(getThreadState(info));


StackTraceElement[] stackTraceElements = ();
for (StackTraceElement each : stackTraceElements) {
(());
}


MonitorInfo[] monitorInfos = ();
for (MonitorInfo each : monitorInfos) {
TMonitorInfo tMonitorInfo = new TMonitorInfo();


(());
(().toString());


(tMonitorInfo);
}


LockInfo[] lockInfos = ();
for (LockInfo lockInfo : lockInfos) {
(());
}


(());
}


("-----------------------------");
}


private static TThreadState getThreadState(ThreadInfo info) {
String stateName = ().name();
for (TThreadState state : ()) {
if (().equalsIgnoreCase(stateName)) {
return state;
}
}
return null;
}
}