-
Notifications
You must be signed in to change notification settings - Fork 515
/
ThreadSnapshot.java
55 lines (44 loc) · 1.44 KB
/
ThreadSnapshot.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.gridkit.jvmtool.stacktrace;
import java.lang.Thread.State;
import java.lang.management.ThreadInfo;
import java.util.Arrays;
public class ThreadSnapshot {
public long threadId;
public String threadName;
public long timestamp;
public StackTraceElement[] elements;
public long[] counters = new long[32];
public State state;
public void copyFrom(ThreadInfo info) {
threadId = info.getThreadId();
threadName = info.getThreadName();
elements = info.getStackTrace();
state = info.getThreadState();
if (info.getBlockedCount() > 0) {
setCounter(ThreadCounter.BLOCKED_COUNTER, info.getBlockedCount());
}
if (info.getBlockedTime() > 0) {
setCounter(ThreadCounter.BLOCKED_TIME, info.getBlockedTime());
}
if (info.getWaitedCount() > 0) {
setCounter(ThreadCounter.WAIT_COUNTER, info.getWaitedCount());
}
if (info.getWaitedTime() > 0) {
setCounter(ThreadCounter.WAIT_TIME, info.getWaitedTime());
}
}
public void setCounter(ThreadCounter c, long value) {
counters[c.ordinal()] = value;
}
public void setCounter(int counterId, long value) {
counters[counterId] = value;
}
public void reset() {
threadId = -1;
threadName = null;
timestamp = -1;
elements = null;
Arrays.fill(counters, -1);
state = null;
}
}