author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 47028 | jdk/src/java.management/share/classes/java/lang/management/ThreadInfo.java@6df65183aa1f |
child 49077 | b1c42b3cd19b |
permissions | -rw-r--r-- |
2 | 1 |
/* |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
42106
diff
changeset
|
2 |
* Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang.management; |
|
27 |
||
28 |
import javax.management.openmbean.CompositeData; |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
29 |
import sun.management.ManagementFactoryHelper; |
2 | 30 |
import sun.management.ThreadInfoCompositeData; |
31 |
import static java.lang.Thread.State.*; |
|
32 |
||
33 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
34 |
* Thread information. {@code ThreadInfo} contains the information |
2 | 35 |
* about a thread including: |
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
14342
diff
changeset
|
36 |
* <h3>General thread information</h3> |
2 | 37 |
* <ul> |
38 |
* <li>Thread ID.</li> |
|
39 |
* <li>Name of the thread.</li> |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
40 |
* <li>Whether a thread is a daemon thread</li> |
2 | 41 |
* </ul> |
42 |
* |
|
18799
31062cb3cc8e
8020308: Fix doclint issues in java.lang.management
sspitsyn
parents:
14342
diff
changeset
|
43 |
* <h3>Execution information</h3> |
2 | 44 |
* <ul> |
45 |
* <li>Thread state.</li> |
|
46 |
* <li>The object upon which the thread is blocked due to: |
|
47 |
* <ul> |
|
48 |
* <li>waiting to enter a synchronization block/method, or</li> |
|
49 |
* <li>waiting to be notified in a {@link Object#wait Object.wait} method, |
|
50 |
* or</li> |
|
51 |
* <li>parking due to a {@link java.util.concurrent.locks.LockSupport#park |
|
52 |
* LockSupport.park} call.</li> |
|
53 |
* </ul> |
|
54 |
* </li> |
|
55 |
* <li>The ID of the thread that owns the object |
|
56 |
* that the thread is blocked.</li> |
|
57 |
* <li>Stack trace of the thread.</li> |
|
58 |
* <li>List of object monitors locked by the thread.</li> |
|
59 |
* <li>List of <a href="LockInfo.html#OwnableSynchronizer"> |
|
60 |
* ownable synchronizers</a> locked by the thread.</li> |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
61 |
* <li>Thread priority</li> |
2 | 62 |
* </ul> |
63 |
* |
|
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
42106
diff
changeset
|
64 |
* <h4><a id="SyncStats">Synchronization Statistics</a></h4> |
2 | 65 |
* <ul> |
66 |
* <li>The number of times that the thread has blocked for |
|
67 |
* synchronization or waited for notification.</li> |
|
68 |
* <li>The accumulated elapsed time that the thread has blocked |
|
69 |
* for synchronization or waited for notification |
|
70 |
* since {@link ThreadMXBean#setThreadContentionMonitoringEnabled |
|
71 |
* thread contention monitoring} |
|
72 |
* was enabled. Some Java virtual machine implementation |
|
73 |
* may not support this. The |
|
74 |
* {@link ThreadMXBean#isThreadContentionMonitoringSupported()} |
|
75 |
* method can be used to determine if a Java virtual machine |
|
76 |
* supports this.</li> |
|
77 |
* </ul> |
|
78 |
* |
|
79 |
* <p>This thread information class is designed for use in monitoring of |
|
80 |
* the system, not for synchronization control. |
|
81 |
* |
|
82 |
* <h4>MXBean Mapping</h4> |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
83 |
* {@code ThreadInfo} is mapped to a {@link CompositeData CompositeData} |
2 | 84 |
* with attributes as specified in |
85 |
* the {@link #from from} method. |
|
86 |
* |
|
87 |
* @see ThreadMXBean#getThreadInfo |
|
88 |
* @see ThreadMXBean#dumpAllThreads |
|
89 |
* |
|
90 |
* @author Mandy Chung |
|
91 |
* @since 1.5 |
|
92 |
*/ |
|
93 |
||
94 |
public class ThreadInfo { |
|
95 |
private String threadName; |
|
96 |
private long threadId; |
|
97 |
private long blockedTime; |
|
98 |
private long blockedCount; |
|
99 |
private long waitedTime; |
|
100 |
private long waitedCount; |
|
101 |
private LockInfo lock; |
|
102 |
private String lockName; |
|
103 |
private long lockOwnerId; |
|
104 |
private String lockOwnerName; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
105 |
private boolean daemon; |
2 | 106 |
private boolean inNative; |
107 |
private boolean suspended; |
|
108 |
private Thread.State threadState; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
109 |
private int priority; |
2 | 110 |
private StackTraceElement[] stackTrace; |
111 |
private MonitorInfo[] lockedMonitors; |
|
112 |
private LockInfo[] lockedSynchronizers; |
|
113 |
||
114 |
private static MonitorInfo[] EMPTY_MONITORS = new MonitorInfo[0]; |
|
115 |
private static LockInfo[] EMPTY_SYNCS = new LockInfo[0]; |
|
116 |
||
117 |
/** |
|
118 |
* Constructor of ThreadInfo created by the JVM |
|
119 |
* |
|
120 |
* @param t Thread |
|
121 |
* @param state Thread state |
|
122 |
* @param lockObj Object on which the thread is blocked |
|
123 |
* @param lockOwner the thread holding the lock |
|
124 |
* @param blockedCount Number of times blocked to enter a lock |
|
125 |
* @param blockedTime Approx time blocked to enter a lock |
|
126 |
* @param waitedCount Number of times waited on a lock |
|
127 |
* @param waitedTime Approx time waited on a lock |
|
128 |
* @param stackTrace Thread stack trace |
|
129 |
*/ |
|
130 |
private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner, |
|
131 |
long blockedCount, long blockedTime, |
|
132 |
long waitedCount, long waitedTime, |
|
133 |
StackTraceElement[] stackTrace) { |
|
134 |
initialize(t, state, lockObj, lockOwner, |
|
135 |
blockedCount, blockedTime, |
|
136 |
waitedCount, waitedTime, stackTrace, |
|
137 |
EMPTY_MONITORS, EMPTY_SYNCS); |
|
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* Constructor of ThreadInfo created by the JVM |
|
142 |
* for {@link ThreadMXBean#getThreadInfo(long[],boolean,boolean)} |
|
143 |
* and {@link ThreadMXBean#dumpAllThreads} |
|
144 |
* |
|
145 |
* @param t Thread |
|
146 |
* @param state Thread state |
|
147 |
* @param lockObj Object on which the thread is blocked |
|
148 |
* @param lockOwner the thread holding the lock |
|
149 |
* @param blockedCount Number of times blocked to enter a lock |
|
150 |
* @param blockedTime Approx time blocked to enter a lock |
|
151 |
* @param waitedCount Number of times waited on a lock |
|
152 |
* @param waitedTime Approx time waited on a lock |
|
153 |
* @param stackTrace Thread stack trace |
|
14014 | 154 |
* @param monitors List of locked monitors |
155 |
* @param stackDepths List of stack depths |
|
156 |
* @param synchronizers List of locked synchronizers |
|
2 | 157 |
*/ |
158 |
private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner, |
|
159 |
long blockedCount, long blockedTime, |
|
160 |
long waitedCount, long waitedTime, |
|
161 |
StackTraceElement[] stackTrace, |
|
162 |
Object[] monitors, |
|
163 |
int[] stackDepths, |
|
164 |
Object[] synchronizers) { |
|
165 |
int numMonitors = (monitors == null ? 0 : monitors.length); |
|
166 |
MonitorInfo[] lockedMonitors; |
|
167 |
if (numMonitors == 0) { |
|
168 |
lockedMonitors = EMPTY_MONITORS; |
|
169 |
} else { |
|
170 |
lockedMonitors = new MonitorInfo[numMonitors]; |
|
171 |
for (int i = 0; i < numMonitors; i++) { |
|
172 |
Object lock = monitors[i]; |
|
173 |
String className = lock.getClass().getName(); |
|
174 |
int identityHashCode = System.identityHashCode(lock); |
|
175 |
int depth = stackDepths[i]; |
|
176 |
StackTraceElement ste = (depth >= 0 ? stackTrace[depth] |
|
177 |
: null); |
|
178 |
lockedMonitors[i] = new MonitorInfo(className, |
|
179 |
identityHashCode, |
|
180 |
depth, |
|
181 |
ste); |
|
182 |
} |
|
183 |
} |
|
184 |
||
185 |
int numSyncs = (synchronizers == null ? 0 : synchronizers.length); |
|
186 |
LockInfo[] lockedSynchronizers; |
|
187 |
if (numSyncs == 0) { |
|
188 |
lockedSynchronizers = EMPTY_SYNCS; |
|
189 |
} else { |
|
190 |
lockedSynchronizers = new LockInfo[numSyncs]; |
|
191 |
for (int i = 0; i < numSyncs; i++) { |
|
192 |
Object lock = synchronizers[i]; |
|
193 |
String className = lock.getClass().getName(); |
|
194 |
int identityHashCode = System.identityHashCode(lock); |
|
195 |
lockedSynchronizers[i] = new LockInfo(className, |
|
196 |
identityHashCode); |
|
197 |
} |
|
198 |
} |
|
199 |
||
200 |
initialize(t, state, lockObj, lockOwner, |
|
201 |
blockedCount, blockedTime, |
|
202 |
waitedCount, waitedTime, stackTrace, |
|
203 |
lockedMonitors, lockedSynchronizers); |
|
204 |
} |
|
205 |
||
206 |
/** |
|
207 |
* Initialize ThreadInfo object |
|
208 |
* |
|
209 |
* @param t Thread |
|
210 |
* @param state Thread state |
|
211 |
* @param lockObj Object on which the thread is blocked |
|
212 |
* @param lockOwner the thread holding the lock |
|
213 |
* @param blockedCount Number of times blocked to enter a lock |
|
214 |
* @param blockedTime Approx time blocked to enter a lock |
|
215 |
* @param waitedCount Number of times waited on a lock |
|
216 |
* @param waitedTime Approx time waited on a lock |
|
217 |
* @param stackTrace Thread stack trace |
|
218 |
* @param lockedMonitors List of locked monitors |
|
219 |
* @param lockedSynchronizers List of locked synchronizers |
|
220 |
*/ |
|
221 |
private void initialize(Thread t, int state, Object lockObj, Thread lockOwner, |
|
222 |
long blockedCount, long blockedTime, |
|
223 |
long waitedCount, long waitedTime, |
|
224 |
StackTraceElement[] stackTrace, |
|
225 |
MonitorInfo[] lockedMonitors, |
|
226 |
LockInfo[] lockedSynchronizers) { |
|
227 |
this.threadId = t.getId(); |
|
228 |
this.threadName = t.getName(); |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
229 |
this.threadState = ManagementFactoryHelper.toThreadState(state); |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
230 |
this.suspended = ManagementFactoryHelper.isThreadSuspended(state); |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
231 |
this.inNative = ManagementFactoryHelper.isThreadRunningNative(state); |
2 | 232 |
this.blockedCount = blockedCount; |
233 |
this.blockedTime = blockedTime; |
|
234 |
this.waitedCount = waitedCount; |
|
235 |
this.waitedTime = waitedTime; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
236 |
this.daemon = t.isDaemon(); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
237 |
this.priority = t.getPriority(); |
2 | 238 |
|
239 |
if (lockObj == null) { |
|
240 |
this.lock = null; |
|
241 |
this.lockName = null; |
|
242 |
} else { |
|
243 |
this.lock = new LockInfo(lockObj); |
|
244 |
this.lockName = |
|
245 |
lock.getClassName() + '@' + |
|
246 |
Integer.toHexString(lock.getIdentityHashCode()); |
|
247 |
} |
|
248 |
if (lockOwner == null) { |
|
249 |
this.lockOwnerId = -1; |
|
250 |
this.lockOwnerName = null; |
|
251 |
} else { |
|
252 |
this.lockOwnerId = lockOwner.getId(); |
|
253 |
this.lockOwnerName = lockOwner.getName(); |
|
254 |
} |
|
255 |
if (stackTrace == null) { |
|
256 |
this.stackTrace = NO_STACK_TRACE; |
|
257 |
} else { |
|
258 |
this.stackTrace = stackTrace; |
|
259 |
} |
|
260 |
this.lockedMonitors = lockedMonitors; |
|
261 |
this.lockedSynchronizers = lockedSynchronizers; |
|
262 |
} |
|
263 |
||
264 |
/* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
265 |
* Constructs a {@code ThreadInfo} object from a |
2 | 266 |
* {@link CompositeData CompositeData}. |
267 |
*/ |
|
268 |
private ThreadInfo(CompositeData cd) { |
|
269 |
ThreadInfoCompositeData ticd = ThreadInfoCompositeData.getInstance(cd); |
|
270 |
||
271 |
threadId = ticd.threadId(); |
|
272 |
threadName = ticd.threadName(); |
|
273 |
blockedTime = ticd.blockedTime(); |
|
274 |
blockedCount = ticd.blockedCount(); |
|
275 |
waitedTime = ticd.waitedTime(); |
|
276 |
waitedCount = ticd.waitedCount(); |
|
277 |
lockName = ticd.lockName(); |
|
278 |
lockOwnerId = ticd.lockOwnerId(); |
|
279 |
lockOwnerName = ticd.lockOwnerName(); |
|
280 |
threadState = ticd.threadState(); |
|
281 |
suspended = ticd.suspended(); |
|
282 |
inNative = ticd.inNative(); |
|
283 |
stackTrace = ticd.stackTrace(); |
|
284 |
||
285 |
// 6.0 attributes |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
286 |
if (ticd.hasV6()) { |
2 | 287 |
lock = ticd.lockInfo(); |
288 |
lockedMonitors = ticd.lockedMonitors(); |
|
289 |
lockedSynchronizers = ticd.lockedSynchronizers(); |
|
290 |
} else { |
|
291 |
// lockInfo is a new attribute added in 1.6 ThreadInfo |
|
292 |
// If cd is a 5.0 version, construct the LockInfo object |
|
293 |
// from the lockName value. |
|
294 |
if (lockName != null) { |
|
295 |
String result[] = lockName.split("@"); |
|
296 |
if (result.length == 2) { |
|
297 |
int identityHashCode = Integer.parseInt(result[1], 16); |
|
298 |
lock = new LockInfo(result[0], identityHashCode); |
|
299 |
} else { |
|
300 |
assert result.length == 2; |
|
301 |
lock = null; |
|
302 |
} |
|
303 |
} else { |
|
304 |
lock = null; |
|
305 |
} |
|
306 |
lockedMonitors = EMPTY_MONITORS; |
|
307 |
lockedSynchronizers = EMPTY_SYNCS; |
|
308 |
} |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
309 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
310 |
// 9.0 attributes |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
311 |
if (ticd.isCurrentVersion()) { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
312 |
daemon = ticd.isDaemon(); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
313 |
priority = ticd.getPriority(); |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
314 |
} else { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
315 |
// Not ideal, but unclear what else we can do. |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
316 |
daemon = false; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
317 |
priority = Thread.NORM_PRIORITY; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
318 |
} |
2 | 319 |
} |
320 |
||
321 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
322 |
* Returns the ID of the thread associated with this {@code ThreadInfo}. |
2 | 323 |
* |
324 |
* @return the ID of the associated thread. |
|
325 |
*/ |
|
326 |
public long getThreadId() { |
|
327 |
return threadId; |
|
328 |
} |
|
329 |
||
330 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
331 |
* Returns the name of the thread associated with this {@code ThreadInfo}. |
2 | 332 |
* |
333 |
* @return the name of the associated thread. |
|
334 |
*/ |
|
335 |
public String getThreadName() { |
|
336 |
return threadName; |
|
337 |
} |
|
338 |
||
339 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
340 |
* Returns the state of the thread associated with this {@code ThreadInfo}. |
2 | 341 |
* |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
342 |
* @return {@code Thread.State} of the associated thread. |
2 | 343 |
*/ |
344 |
public Thread.State getThreadState() { |
|
345 |
return threadState; |
|
346 |
} |
|
347 |
||
348 |
/** |
|
349 |
* Returns the approximate accumulated elapsed time (in milliseconds) |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
350 |
* that the thread associated with this {@code ThreadInfo} |
2 | 351 |
* has blocked to enter or reenter a monitor |
352 |
* since thread contention monitoring is enabled. |
|
353 |
* I.e. the total accumulated time the thread has been in the |
|
354 |
* {@link java.lang.Thread.State#BLOCKED BLOCKED} state since thread |
|
355 |
* contention monitoring was last enabled. |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
356 |
* This method returns {@code -1} if thread contention monitoring |
2 | 357 |
* is disabled. |
358 |
* |
|
359 |
* <p>The Java virtual machine may measure the time with a high |
|
360 |
* resolution timer. This statistic is reset when |
|
361 |
* the thread contention monitoring is reenabled. |
|
362 |
* |
|
363 |
* @return the approximate accumulated elapsed time in milliseconds |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
364 |
* that a thread entered the {@code BLOCKED} state; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
365 |
* {@code -1} if thread contention monitoring is disabled. |
2 | 366 |
* |
367 |
* @throws java.lang.UnsupportedOperationException if the Java |
|
368 |
* virtual machine does not support this operation. |
|
369 |
* |
|
370 |
* @see ThreadMXBean#isThreadContentionMonitoringSupported |
|
371 |
* @see ThreadMXBean#setThreadContentionMonitoringEnabled |
|
372 |
*/ |
|
373 |
public long getBlockedTime() { |
|
374 |
return blockedTime; |
|
375 |
} |
|
376 |
||
377 |
/** |
|
378 |
* Returns the total number of times that |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
379 |
* the thread associated with this {@code ThreadInfo} |
2 | 380 |
* blocked to enter or reenter a monitor. |
381 |
* I.e. the number of times a thread has been in the |
|
382 |
* {@link java.lang.Thread.State#BLOCKED BLOCKED} state. |
|
383 |
* |
|
384 |
* @return the total number of times that the thread |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
385 |
* entered the {@code BLOCKED} state. |
2 | 386 |
*/ |
387 |
public long getBlockedCount() { |
|
388 |
return blockedCount; |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
* Returns the approximate accumulated elapsed time (in milliseconds) |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
393 |
* that the thread associated with this {@code ThreadInfo} |
2 | 394 |
* has waited for notification |
395 |
* since thread contention monitoring is enabled. |
|
396 |
* I.e. the total accumulated time the thread has been in the |
|
397 |
* {@link java.lang.Thread.State#WAITING WAITING} |
|
398 |
* or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state |
|
399 |
* since thread contention monitoring is enabled. |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
400 |
* This method returns {@code -1} if thread contention monitoring |
2 | 401 |
* is disabled. |
402 |
* |
|
403 |
* <p>The Java virtual machine may measure the time with a high |
|
404 |
* resolution timer. This statistic is reset when |
|
405 |
* the thread contention monitoring is reenabled. |
|
406 |
* |
|
407 |
* @return the approximate accumulated elapsed time in milliseconds |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
408 |
* that a thread has been in the {@code WAITING} or |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
409 |
* {@code TIMED_WAITING} state; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
410 |
* {@code -1} if thread contention monitoring is disabled. |
2 | 411 |
* |
412 |
* @throws java.lang.UnsupportedOperationException if the Java |
|
413 |
* virtual machine does not support this operation. |
|
414 |
* |
|
415 |
* @see ThreadMXBean#isThreadContentionMonitoringSupported |
|
416 |
* @see ThreadMXBean#setThreadContentionMonitoringEnabled |
|
417 |
*/ |
|
418 |
public long getWaitedTime() { |
|
419 |
return waitedTime; |
|
420 |
} |
|
421 |
||
422 |
/** |
|
423 |
* Returns the total number of times that |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
424 |
* the thread associated with this {@code ThreadInfo} |
2 | 425 |
* waited for notification. |
426 |
* I.e. the number of times that a thread has been |
|
427 |
* in the {@link java.lang.Thread.State#WAITING WAITING} |
|
428 |
* or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state. |
|
429 |
* |
|
430 |
* @return the total number of times that the thread |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
431 |
* was in the {@code WAITING} or {@code TIMED_WAITING} state. |
2 | 432 |
*/ |
433 |
public long getWaitedCount() { |
|
434 |
return waitedCount; |
|
435 |
} |
|
436 |
||
437 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
438 |
* Returns the {@code LockInfo} of an object for which |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
439 |
* the thread associated with this {@code ThreadInfo} |
2 | 440 |
* is blocked waiting. |
441 |
* A thread can be blocked waiting for one of the following: |
|
442 |
* <ul> |
|
443 |
* <li>an object monitor to be acquired for entering or reentering |
|
444 |
* a synchronization block/method. |
|
445 |
* <br>The thread is in the {@link java.lang.Thread.State#BLOCKED BLOCKED} |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
446 |
* state waiting to enter the {@code synchronized} statement |
2 | 447 |
* or method. |
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
21278
diff
changeset
|
448 |
* </li> |
2 | 449 |
* <li>an object monitor to be notified by another thread. |
450 |
* <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING} |
|
451 |
* or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state |
|
452 |
* due to a call to the {@link Object#wait Object.wait} method. |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
21278
diff
changeset
|
453 |
* </li> |
2 | 454 |
* <li>a synchronization object responsible for the thread parking. |
455 |
* <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING} |
|
456 |
* or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state |
|
457 |
* due to a call to the |
|
458 |
* {@link java.util.concurrent.locks.LockSupport#park(Object) |
|
459 |
* LockSupport.park} method. The synchronization object |
|
460 |
* is the object returned from |
|
461 |
* {@link java.util.concurrent.locks.LockSupport#getBlocker |
|
462 |
* LockSupport.getBlocker} method. Typically it is an |
|
463 |
* <a href="LockInfo.html#OwnableSynchronizer"> ownable synchronizer</a> |
|
464 |
* or a {@link java.util.concurrent.locks.Condition Condition}.</li> |
|
465 |
* </ul> |
|
466 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
467 |
* <p>This method returns {@code null} if the thread is not in any of |
2 | 468 |
* the above conditions. |
469 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
470 |
* @return {@code LockInfo} of an object for which the thread |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
471 |
* is blocked waiting if any; {@code null} otherwise. |
2 | 472 |
* @since 1.6 |
473 |
*/ |
|
474 |
public LockInfo getLockInfo() { |
|
475 |
return lock; |
|
476 |
} |
|
477 |
||
478 |
/** |
|
479 |
* Returns the {@link LockInfo#toString string representation} |
|
480 |
* of an object for which the thread associated with this |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
481 |
* {@code ThreadInfo} is blocked waiting. |
2 | 482 |
* This method is equivalent to calling: |
483 |
* <blockquote> |
|
484 |
* <pre> |
|
485 |
* getLockInfo().toString() |
|
486 |
* </pre></blockquote> |
|
487 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
488 |
* <p>This method will return {@code null} if this thread is not blocked |
2 | 489 |
* waiting for any object or if the object is not owned by any thread. |
490 |
* |
|
491 |
* @return the string representation of the object on which |
|
492 |
* the thread is blocked if any; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
493 |
* {@code null} otherwise. |
2 | 494 |
* |
495 |
* @see #getLockInfo |
|
496 |
*/ |
|
497 |
public String getLockName() { |
|
498 |
return lockName; |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
* Returns the ID of the thread which owns the object |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
503 |
* for which the thread associated with this {@code ThreadInfo} |
2 | 504 |
* is blocked waiting. |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
505 |
* This method will return {@code -1} if this thread is not blocked |
2 | 506 |
* waiting for any object or if the object is not owned by any thread. |
507 |
* |
|
508 |
* @return the thread ID of the owner thread of the object |
|
509 |
* this thread is blocked on; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
510 |
* {@code -1} if this thread is not blocked |
21278 | 511 |
* or if the object is not owned by any thread. |
2 | 512 |
* |
513 |
* @see #getLockInfo |
|
514 |
*/ |
|
515 |
public long getLockOwnerId() { |
|
516 |
return lockOwnerId; |
|
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Returns the name of the thread which owns the object |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
521 |
* for which the thread associated with this {@code ThreadInfo} |
2 | 522 |
* is blocked waiting. |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
523 |
* This method will return {@code null} if this thread is not blocked |
2 | 524 |
* waiting for any object or if the object is not owned by any thread. |
525 |
* |
|
526 |
* @return the name of the thread that owns the object |
|
527 |
* this thread is blocked on; |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
528 |
* {@code null} if this thread is not blocked |
2 | 529 |
* or if the object is not owned by any thread. |
530 |
* |
|
531 |
* @see #getLockInfo |
|
532 |
*/ |
|
533 |
public String getLockOwnerName() { |
|
534 |
return lockOwnerName; |
|
535 |
} |
|
536 |
||
537 |
/** |
|
538 |
* Returns the stack trace of the thread |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
539 |
* associated with this {@code ThreadInfo}. |
2 | 540 |
* If no stack trace was requested for this thread info, this method |
541 |
* will return a zero-length array. |
|
542 |
* If the returned array is of non-zero length then the first element of |
|
543 |
* the array represents the top of the stack, which is the most recent |
|
544 |
* method invocation in the sequence. The last element of the array |
|
545 |
* represents the bottom of the stack, which is the least recent method |
|
546 |
* invocation in the sequence. |
|
547 |
* |
|
548 |
* <p>Some Java virtual machines may, under some circumstances, omit one |
|
549 |
* or more stack frames from the stack trace. In the extreme case, |
|
550 |
* a virtual machine that has no stack trace information concerning |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
551 |
* the thread associated with this {@code ThreadInfo} |
2 | 552 |
* is permitted to return a zero-length array from this method. |
553 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
554 |
* @return an array of {@code StackTraceElement} objects of the thread. |
2 | 555 |
*/ |
556 |
public StackTraceElement[] getStackTrace() { |
|
42106
90fc3dc00723
8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents:
40184
diff
changeset
|
557 |
return stackTrace.clone(); |
2 | 558 |
} |
559 |
||
560 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
561 |
* Tests if the thread associated with this {@code ThreadInfo} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
562 |
* is suspended. This method returns {@code true} if |
2 | 563 |
* {@link Thread#suspend} has been called. |
564 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
565 |
* @return {@code true} if the thread is suspended; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
566 |
* {@code false} otherwise. |
2 | 567 |
*/ |
568 |
public boolean isSuspended() { |
|
569 |
return suspended; |
|
570 |
} |
|
571 |
||
572 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
573 |
* Tests if the thread associated with this {@code ThreadInfo} |
2 | 574 |
* is executing native code via the Java Native Interface (JNI). |
575 |
* The JNI native code does not include |
|
576 |
* the virtual machine support code or the compiled native |
|
577 |
* code generated by the virtual machine. |
|
578 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
579 |
* @return {@code true} if the thread is executing native code; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
580 |
* {@code false} otherwise. |
2 | 581 |
*/ |
582 |
public boolean isInNative() { |
|
583 |
return inNative; |
|
584 |
} |
|
585 |
||
586 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
587 |
* Tests if the thread associated with this {@code ThreadInfo} is |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
588 |
* a {@linkplain Thread#isDaemon daemon thread}. |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
589 |
* |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
590 |
* @return {@code true} if the thread is a daemon thread, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
591 |
* {@code false} otherwise. |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
592 |
* @see Thread#isDaemon |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
29101
diff
changeset
|
593 |
* @since 9 |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
594 |
*/ |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
595 |
public boolean isDaemon() { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
596 |
return daemon; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
597 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
598 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
599 |
/** |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
600 |
* Returns the {@linkplain Thread#getPriority() thread priority} of the |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
601 |
* thread associated with this {@code ThreadInfo}. |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
602 |
* |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
603 |
* @return The priority of the thread associated with this |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
604 |
* {@code ThreadInfo}. |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
29101
diff
changeset
|
605 |
* @since 9 |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
606 |
*/ |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
607 |
public int getPriority() { |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
608 |
return priority; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
609 |
} |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
610 |
|
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
611 |
/** |
2 | 612 |
* Returns a string representation of this thread info. |
613 |
* The format of this string depends on the implementation. |
|
614 |
* The returned string will typically include |
|
615 |
* the {@linkplain #getThreadName thread name}, |
|
616 |
* the {@linkplain #getThreadId thread ID}, |
|
617 |
* its {@linkplain #getThreadState state}, |
|
618 |
* and a {@linkplain #getStackTrace stack trace} if any. |
|
619 |
* |
|
620 |
* @return a string representation of this thread info. |
|
621 |
*/ |
|
622 |
public String toString() { |
|
623 |
StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" + |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
624 |
(daemon ? " daemon" : "") + |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
625 |
" prio=" + priority + |
2 | 626 |
" Id=" + getThreadId() + " " + |
627 |
getThreadState()); |
|
628 |
if (getLockName() != null) { |
|
629 |
sb.append(" on " + getLockName()); |
|
630 |
} |
|
631 |
if (getLockOwnerName() != null) { |
|
632 |
sb.append(" owned by \"" + getLockOwnerName() + |
|
633 |
"\" Id=" + getLockOwnerId()); |
|
634 |
} |
|
635 |
if (isSuspended()) { |
|
636 |
sb.append(" (suspended)"); |
|
637 |
} |
|
638 |
if (isInNative()) { |
|
639 |
sb.append(" (in native)"); |
|
640 |
} |
|
641 |
sb.append('\n'); |
|
642 |
int i = 0; |
|
643 |
for (; i < stackTrace.length && i < MAX_FRAMES; i++) { |
|
644 |
StackTraceElement ste = stackTrace[i]; |
|
645 |
sb.append("\tat " + ste.toString()); |
|
646 |
sb.append('\n'); |
|
647 |
if (i == 0 && getLockInfo() != null) { |
|
648 |
Thread.State ts = getThreadState(); |
|
649 |
switch (ts) { |
|
650 |
case BLOCKED: |
|
651 |
sb.append("\t- blocked on " + getLockInfo()); |
|
652 |
sb.append('\n'); |
|
653 |
break; |
|
654 |
case WAITING: |
|
655 |
sb.append("\t- waiting on " + getLockInfo()); |
|
656 |
sb.append('\n'); |
|
657 |
break; |
|
658 |
case TIMED_WAITING: |
|
659 |
sb.append("\t- waiting on " + getLockInfo()); |
|
660 |
sb.append('\n'); |
|
661 |
break; |
|
662 |
default: |
|
663 |
} |
|
664 |
} |
|
665 |
||
666 |
for (MonitorInfo mi : lockedMonitors) { |
|
667 |
if (mi.getLockedStackDepth() == i) { |
|
668 |
sb.append("\t- locked " + mi); |
|
669 |
sb.append('\n'); |
|
670 |
} |
|
671 |
} |
|
672 |
} |
|
673 |
if (i < stackTrace.length) { |
|
674 |
sb.append("\t..."); |
|
675 |
sb.append('\n'); |
|
676 |
} |
|
677 |
||
678 |
LockInfo[] locks = getLockedSynchronizers(); |
|
679 |
if (locks.length > 0) { |
|
680 |
sb.append("\n\tNumber of locked synchronizers = " + locks.length); |
|
681 |
sb.append('\n'); |
|
682 |
for (LockInfo li : locks) { |
|
683 |
sb.append("\t- " + li); |
|
684 |
sb.append('\n'); |
|
685 |
} |
|
686 |
} |
|
687 |
sb.append('\n'); |
|
688 |
return sb.toString(); |
|
689 |
} |
|
690 |
private static final int MAX_FRAMES = 8; |
|
691 |
||
692 |
/** |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
693 |
* Returns a {@code ThreadInfo} object represented by the |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
694 |
* given {@code CompositeData}. |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
695 |
* The given {@code CompositeData} must contain the following attributes |
2 | 696 |
* unless otherwise specified below: |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
697 |
* <table class="striped" style="margin-left:2em"> |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
42106
diff
changeset
|
698 |
* <caption style="display:none">The attributes and their types the given CompositeData contains</caption> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
699 |
* <thead> |
2 | 700 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
701 |
* <th scope="col">Attribute Name</th> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
702 |
* <th scope="col">Type</th> |
2 | 703 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
704 |
* </thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
705 |
* <tbody style="text-align:left"> |
2 | 706 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
707 |
* <th scope="row">threadId</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
708 |
* <td>{@code java.lang.Long}</td> |
2 | 709 |
* </tr> |
710 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
711 |
* <th scope="row">threadName</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
712 |
* <td>{@code java.lang.String}</td> |
2 | 713 |
* </tr> |
714 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
715 |
* <th scope="row">threadState</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
716 |
* <td>{@code java.lang.String}</td> |
2 | 717 |
* </tr> |
718 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
719 |
* <th scope="row">suspended</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
720 |
* <td>{@code java.lang.Boolean}</td> |
2 | 721 |
* </tr> |
722 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
723 |
* <th scope="row">inNative</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
724 |
* <td>{@code java.lang.Boolean}</td> |
2 | 725 |
* </tr> |
726 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
727 |
* <th scope="row">blockedCount</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
728 |
* <td>{@code java.lang.Long}</td> |
2 | 729 |
* </tr> |
730 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
731 |
* <th scope="row">blockedTime</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
732 |
* <td>{@code java.lang.Long}</td> |
2 | 733 |
* </tr> |
734 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
735 |
* <th scope="row">waitedCount</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
736 |
* <td>{@code java.lang.Long}</td> |
2 | 737 |
* </tr> |
738 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
739 |
* <th scope="row">waitedTime</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
740 |
* <td>{@code java.lang.Long}</td> |
2 | 741 |
* </tr> |
742 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
743 |
* <th scope="row">lockInfo</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
744 |
* <td>{@code javax.management.openmbean.CompositeData} |
2 | 745 |
* - the mapped type for {@link LockInfo} as specified in the |
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
746 |
* {@link LockInfo#from} method. |
2 | 747 |
* <p> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
748 |
* If {@code cd} does not contain this attribute, |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
749 |
* the {@code LockInfo} object will be constructed from |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
750 |
* the value of the {@code lockName} attribute. </td> |
2 | 751 |
* </tr> |
752 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
753 |
* <th scope="row">lockName</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
754 |
* <td>{@code java.lang.String}</td> |
2 | 755 |
* </tr> |
756 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
757 |
* <th scope="row">lockOwnerId</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
758 |
* <td>{@code java.lang.Long}</td> |
2 | 759 |
* </tr> |
760 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
761 |
* <th scope="row">lockOwnerName</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
762 |
* <td>{@code java.lang.String}</td> |
2 | 763 |
* </tr> |
764 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
765 |
* <th scope="row"><a id="StackTrace">stackTrace</a></th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
766 |
* <td>{@code javax.management.openmbean.CompositeData[]} |
2 | 767 |
* <p> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
768 |
* Each element is a {@code CompositeData} representing |
2 | 769 |
* StackTraceElement containing the following attributes: |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
770 |
* <table class="striped" style="margin-left:2em"> |
44858
7183899b064b
8179415: Update java.management and java.management.rmi to be HTML-5 friendly
ksrini
parents:
42106
diff
changeset
|
771 |
* <caption style="display:none">The attributes and their types the given CompositeData contains</caption> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
772 |
* <thead style="text-align:center"> |
2 | 773 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
774 |
* <th scope="col">Attribute Name</th> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
775 |
* <th scope="col">Type</th> |
2 | 776 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
777 |
* </thead> |
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
778 |
* <tbody style="text-align:left"> |
2 | 779 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
780 |
* <th scope="row">moduleName</th> |
40184
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
781 |
* <td>{@code java.lang.String}</td> |
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
782 |
* </tr> |
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
783 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
784 |
* <th scope="row">moduleVersion</th> |
40184
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
785 |
* <td>{@code java.lang.String}</td> |
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
786 |
* </tr> |
aed163cc3cc2
8158350: Table in ThreadInfo.from(CompositeData) may need updates for new stack trace attributes
sspitsyn
parents:
35302
diff
changeset
|
787 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
788 |
* <th scope="row">className</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
789 |
* <td>{@code java.lang.String}</td> |
2 | 790 |
* </tr> |
791 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
792 |
* <th scope="row">methodName</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
793 |
* <td>{@code java.lang.String}</td> |
2 | 794 |
* </tr> |
795 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
796 |
* <th scope="row">fileName</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
797 |
* <td>{@code java.lang.String}</td> |
2 | 798 |
* </tr> |
799 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
800 |
* <th scope="row">lineNumber</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
801 |
* <td>{@code java.lang.Integer}</td> |
2 | 802 |
* </tr> |
803 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
804 |
* <th scope="row">nativeMethod</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
805 |
* <td>{@code java.lang.Boolean}</td> |
2 | 806 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
807 |
* </tbody> |
2 | 808 |
* </table> |
809 |
* </td> |
|
810 |
* </tr> |
|
811 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
812 |
* <th scope="row">lockedMonitors</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
813 |
* <td>{@code javax.management.openmbean.CompositeData[]} |
2 | 814 |
* whose element type is the mapped type for |
815 |
* {@link MonitorInfo} as specified in the |
|
816 |
* {@link MonitorInfo#from Monitor.from} method. |
|
817 |
* <p> |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
818 |
* If {@code cd} does not contain this attribute, |
2 | 819 |
* this attribute will be set to an empty array. </td> |
820 |
* </tr> |
|
821 |
* <tr> |
|
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
822 |
* <th scope="row">lockedSynchronizers</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
823 |
* <td>{@code javax.management.openmbean.CompositeData[]} |
2 | 824 |
* whose element type is the mapped type for |
13803
889df16bef60
7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents:
5506
diff
changeset
|
825 |
* {@link LockInfo} as specified in the {@link LockInfo#from} method. |
2 | 826 |
* <p> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
827 |
* If {@code cd} does not contain this attribute, |
2 | 828 |
* this attribute will be set to an empty array. </td> |
829 |
* </tr> |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
830 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
831 |
* <th scope="row">daemon</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
832 |
* <td>{@code java.lang.Boolean}</td> |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
833 |
* </tr> |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
834 |
* <tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
835 |
* <th scope="row">priority</th> |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
836 |
* <td>{@code java.lang.Integer}</td> |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
837 |
* </tr> |
47028
6df65183aa1f
8186932: Fix accessibility issues in the java.management module
jjg
parents:
45130
diff
changeset
|
838 |
* </tbody> |
2 | 839 |
* </table> |
840 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
841 |
* @param cd {@code CompositeData} representing a {@code ThreadInfo} |
2 | 842 |
* |
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
843 |
* @throws IllegalArgumentException if {@code cd} does not |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
844 |
* represent a {@code ThreadInfo} with the attributes described |
2 | 845 |
* above. |
846 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
847 |
* @return a {@code ThreadInfo} object represented |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
848 |
* by {@code cd} if {@code cd} is not {@code null}; |
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
849 |
* {@code null} otherwise. |
45004
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
42106
diff
changeset
|
850 |
* |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
42106
diff
changeset
|
851 |
* @revised 9 |
ea3137042a61
8178380: Module system implementation refresh (5/2017)
alanb
parents:
42106
diff
changeset
|
852 |
* @spec JPMS |
2 | 853 |
*/ |
854 |
public static ThreadInfo from(CompositeData cd) { |
|
855 |
if (cd == null) { |
|
856 |
return null; |
|
857 |
} |
|
858 |
||
859 |
if (cd instanceof ThreadInfoCompositeData) { |
|
860 |
return ((ThreadInfoCompositeData) cd).getThreadInfo(); |
|
861 |
} else { |
|
862 |
return new ThreadInfo(cd); |
|
863 |
} |
|
864 |
} |
|
865 |
||
866 |
/** |
|
867 |
* Returns an array of {@link MonitorInfo} objects, each of which |
|
868 |
* represents an object monitor currently locked by the thread |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
869 |
* associated with this {@code ThreadInfo}. |
2 | 870 |
* If no locked monitor was requested for this thread info or |
871 |
* no monitor is locked by the thread, this method |
|
872 |
* will return a zero-length array. |
|
873 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
874 |
* @return an array of {@code MonitorInfo} objects representing |
2 | 875 |
* the object monitors locked by the thread. |
876 |
* |
|
877 |
* @since 1.6 |
|
878 |
*/ |
|
879 |
public MonitorInfo[] getLockedMonitors() { |
|
42106
90fc3dc00723
8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents:
40184
diff
changeset
|
880 |
return lockedMonitors.clone(); |
2 | 881 |
} |
882 |
||
883 |
/** |
|
884 |
* Returns an array of {@link LockInfo} objects, each of which |
|
885 |
* represents an <a href="LockInfo.html#OwnableSynchronizer">ownable |
|
886 |
* synchronizer</a> currently locked by the thread associated with |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
887 |
* this {@code ThreadInfo}. If no locked synchronizer was |
2 | 888 |
* requested for this thread info or no synchronizer is locked by |
889 |
* the thread, this method will return a zero-length array. |
|
890 |
* |
|
29101
55f7a91aaa32
6588467: Add isDaemon() and getPriority() to ThreadInfo
jmanson
parents:
25859
diff
changeset
|
891 |
* @return an array of {@code LockInfo} objects representing |
2 | 892 |
* the ownable synchronizers locked by the thread. |
893 |
* |
|
894 |
* @since 1.6 |
|
895 |
*/ |
|
896 |
public LockInfo[] getLockedSynchronizers() { |
|
42106
90fc3dc00723
8006078: [findbugs] java.lang.management.ThreadInfo returns mutable objects
vtewari
parents:
40184
diff
changeset
|
897 |
return lockedSynchronizers.clone(); |
2 | 898 |
} |
899 |
||
900 |
private static final StackTraceElement[] NO_STACK_TRACE = |
|
901 |
new StackTraceElement[0]; |
|
902 |
} |