ThreadUtils.java
7.21 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package org.apache.commons.lang3;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class ThreadUtils
{
public static final a ALWAYS_TRUE_PREDICATE = new a((byte)0);
public static Thread findThreadById(long paramLong)
{
Collection localCollection = findThreads(new ThreadIdPredicate(paramLong));
if (localCollection.isEmpty()) {
return null;
}
return (Thread)localCollection.iterator().next();
}
public static Thread findThreadById(long paramLong, String paramString)
{
if (paramString == null) {
throw new IllegalArgumentException("The thread group name must not be null");
}
Thread localThread = findThreadById(paramLong);
if ((localThread != null) && (localThread.getThreadGroup() != null) && (localThread.getThreadGroup().getName().equals(paramString))) {
return localThread;
}
return null;
}
public static Thread findThreadById(long paramLong, ThreadGroup paramThreadGroup)
{
if (paramThreadGroup == null) {
throw new IllegalArgumentException("The thread group must not be null");
}
Thread localThread = findThreadById(paramLong);
if ((localThread != null) && (paramThreadGroup.equals(localThread.getThreadGroup()))) {
return localThread;
}
return null;
}
public static Collection<ThreadGroup> findThreadGroups(ThreadGroup paramThreadGroup, boolean paramBoolean, ThreadGroupPredicate paramThreadGroupPredicate)
{
if (paramThreadGroup == null) {
throw new IllegalArgumentException("The group must not be null");
}
if (paramThreadGroupPredicate == null) {
throw new IllegalArgumentException("The predicate must not be null");
}
int i = paramThreadGroup.activeGroupCount();
ThreadGroup[] arrayOfThreadGroup;
int j;
do
{
arrayOfThreadGroup = new ThreadGroup[i + i / 2 + 1];
j = paramThreadGroup.enumerate(arrayOfThreadGroup, paramBoolean);
i = j;
} while (j >= arrayOfThreadGroup.length);
paramThreadGroup = new ArrayList(j);
i = 0;
while (i < j)
{
if (paramThreadGroupPredicate.test(arrayOfThreadGroup[i])) {
paramThreadGroup.add(arrayOfThreadGroup[i]);
}
i += 1;
}
return Collections.unmodifiableCollection(paramThreadGroup);
}
public static Collection<ThreadGroup> findThreadGroups(ThreadGroupPredicate paramThreadGroupPredicate)
{
return findThreadGroups(getSystemThreadGroup(), true, paramThreadGroupPredicate);
}
public static Collection<ThreadGroup> findThreadGroupsByName(String paramString)
{
return findThreadGroups(new NamePredicate(paramString));
}
public static Collection<Thread> findThreads(ThreadGroup paramThreadGroup, boolean paramBoolean, ThreadPredicate paramThreadPredicate)
{
if (paramThreadGroup == null) {
throw new IllegalArgumentException("The group must not be null");
}
if (paramThreadPredicate == null) {
throw new IllegalArgumentException("The predicate must not be null");
}
int i = paramThreadGroup.activeCount();
Thread[] arrayOfThread;
int j;
do
{
arrayOfThread = new Thread[i + i / 2 + 1];
j = paramThreadGroup.enumerate(arrayOfThread, paramBoolean);
i = j;
} while (j >= arrayOfThread.length);
paramThreadGroup = new ArrayList(j);
i = 0;
while (i < j)
{
if (paramThreadPredicate.test(arrayOfThread[i])) {
paramThreadGroup.add(arrayOfThread[i]);
}
i += 1;
}
return Collections.unmodifiableCollection(paramThreadGroup);
}
public static Collection<Thread> findThreads(ThreadPredicate paramThreadPredicate)
{
return findThreads(getSystemThreadGroup(), true, paramThreadPredicate);
}
public static Collection<Thread> findThreadsByName(String paramString)
{
return findThreads(new NamePredicate(paramString));
}
public static Collection<Thread> findThreadsByName(String paramString1, String paramString2)
{
if (paramString1 == null) {
throw new IllegalArgumentException("The thread name must not be null");
}
if (paramString2 == null) {
throw new IllegalArgumentException("The thread group name must not be null");
}
Object localObject = findThreadGroups(new NamePredicate(paramString2));
if (((Collection)localObject).isEmpty()) {
return Collections.emptyList();
}
paramString2 = new ArrayList();
paramString1 = new NamePredicate(paramString1);
localObject = ((Collection)localObject).iterator();
while (((Iterator)localObject).hasNext()) {
paramString2.addAll(findThreads((ThreadGroup)((Iterator)localObject).next(), false, paramString1));
}
return Collections.unmodifiableCollection(paramString2);
}
public static Collection<Thread> findThreadsByName(String paramString, ThreadGroup paramThreadGroup)
{
return findThreads(paramThreadGroup, false, new NamePredicate(paramString));
}
public static Collection<ThreadGroup> getAllThreadGroups()
{
return findThreadGroups(ALWAYS_TRUE_PREDICATE);
}
public static Collection<Thread> getAllThreads()
{
return findThreads(ALWAYS_TRUE_PREDICATE);
}
public static ThreadGroup getSystemThreadGroup()
{
for (ThreadGroup localThreadGroup = Thread.currentThread().getThreadGroup(); localThreadGroup.getParent() != null; localThreadGroup = localThreadGroup.getParent()) {}
return localThreadGroup;
}
public static class NamePredicate
implements ThreadUtils.ThreadGroupPredicate, ThreadUtils.ThreadPredicate
{
private final String a;
public NamePredicate(String paramString)
{
if (paramString == null) {
throw new IllegalArgumentException("The name must not be null");
}
this.a = paramString;
}
public boolean test(Thread paramThread)
{
return (paramThread != null) && (paramThread.getName().equals(this.a));
}
public boolean test(ThreadGroup paramThreadGroup)
{
return (paramThreadGroup != null) && (paramThreadGroup.getName().equals(this.a));
}
}
public static abstract interface ThreadGroupPredicate
{
public abstract boolean test(ThreadGroup paramThreadGroup);
}
public static class ThreadIdPredicate
implements ThreadUtils.ThreadPredicate
{
private final long a;
public ThreadIdPredicate(long paramLong)
{
if (paramLong <= 0L) {
throw new IllegalArgumentException("The thread id must be greater than zero");
}
this.a = paramLong;
}
public boolean test(Thread paramThread)
{
return (paramThread != null) && (paramThread.getId() == this.a);
}
}
public static abstract interface ThreadPredicate
{
public abstract boolean test(Thread paramThread);
}
static final class a
implements ThreadUtils.ThreadGroupPredicate, ThreadUtils.ThreadPredicate
{
public final boolean test(Thread paramThread)
{
return true;
}
public final boolean test(ThreadGroup paramThreadGroup)
{
return true;
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/org/apache/commons/lang3/ThreadUtils.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/