1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.logging.log4j.message;
18
19
20
21
22 class BasicThreadInformation implements ThreadInformation {
23 private static final int HASH_SHIFT = 32;
24 private static final int HASH_MULTIPLIER = 31;
25 private final long id;
26 private final String name;
27 private final String longName;
28 private final Thread.State state;
29 private final int priority;
30 private final boolean isAlive;
31 private final boolean isDaemon;
32 private final String threadGroupName;
33
34
35
36
37
38 public BasicThreadInformation(Thread thread) {
39 this.id = thread.getId();
40 this.name = thread.getName();
41 this.longName = thread.toString();
42 this.state = thread.getState();
43 this.priority = thread.getPriority();
44 this.isAlive = thread.isAlive();
45 this.isDaemon = thread.isDaemon();
46 ThreadGroup group = thread.getThreadGroup();
47 threadGroupName = group == null ? null : group.getName();
48 }
49
50 @Override
51 public boolean equals(Object o) {
52 if (this == o) {
53 return true;
54 }
55 if (o == null || getClass() != o.getClass()) {
56 return false;
57 }
58
59 BasicThreadInformation that = (BasicThreadInformation) o;
60
61 if (id != that.id) {
62 return false;
63 }
64 if (name != null ? !name.equals(that.name) : that.name != null) {
65 return false;
66 }
67
68 return true;
69 }
70
71 @Override
72 public int hashCode() {
73 int result = (int) (id ^ (id >>> HASH_SHIFT));
74 result = HASH_MULTIPLIER * result + (name != null ? name.hashCode() : 0);
75 return result;
76 }
77
78
79
80
81
82 public void printThreadInfo(StringBuilder sb) {
83 sb.append("\"").append(name).append("\" ");
84 if (isDaemon) {
85 sb.append("daemon ");
86 }
87 sb.append("prio=").append(priority).append(" tid=").append(id).append(" ");
88 if (threadGroupName != null) {
89 sb.append("group=\"").append(threadGroupName).append("\"");
90 }
91 sb.append("\n");
92 sb.append("\tThread state: ").append(state.name()).append("\n");
93 }
94
95
96
97
98
99
100 public void printStack(StringBuilder sb, StackTraceElement[] trace) {
101 for (StackTraceElement element : trace) {
102 sb.append("\tat ").append(element).append("\n");
103 }
104 }
105 }