001 /*
002 * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.lang.management;
027
028 import java.util.Map;
029
030 /**
031 * The management interface for the thread system of
032 * the Java virtual machine.
033 *
034 * <p> A Java virtual machine has a single instance of the implementation
035 * class of this interface. This instance implementing this interface is
036 * an <a href="ManagementFactory.html#MXBean">MXBean</a>
037 * that can be obtained by calling
038 * the {@link ManagementFactory#getThreadMXBean} method or
039 * from the {@link ManagementFactory#getPlatformMBeanServer
040 * platform <tt>MBeanServer</tt>} method.
041 *
042 * <p>The <tt>ObjectName</tt> for uniquely identifying the MXBean for
043 * the thread system within an MBeanServer is:
044 * <blockquote>
045 * {@link ManagementFactory#THREAD_MXBEAN_NAME
046 * <tt>java.lang:type=Threading</tt>}
047 * </blockquote>
048 *
049 * <h4>Thread ID</h4>
050 * Thread ID is a positive long value returned by calling the
051 * {@link java.lang.Thread#getId} method for a thread.
052 * The thread ID is unique during its lifetime. When a thread
053 * is terminated, this thread ID may be reused.
054 *
055 * <p> Some methods in this interface take a thread ID or an array
056 * of thread IDs as the input parameter and return per-thread information.
057 *
058 * <h4>Thread CPU time</h4>
059 * A Java virtual machine implementation may support measuring
060 * the CPU time for the current thread, for any thread, or for no threads.
061 *
062 * <p>
063 * The {@link #isThreadCpuTimeSupported} method can be used to determine
064 * if a Java virtual machine supports measuring of the CPU time for any
065 * thread. The {@link #isCurrentThreadCpuTimeSupported} method can
066 * be used to determine if a Java virtual machine supports measuring of
067 * the CPU time for the current thread.
068 * A Java virtual machine implementation that supports CPU time measurement
069 * for any thread will also support that for the current thread.
070 *
071 * <p> The CPU time provided by this interface has nanosecond precision
072 * but not necessarily nanosecond accuracy.
073 *
074 * <p>
075 * A Java virtual machine may disable CPU time measurement
076 * by default.
077 * The {@link #isThreadCpuTimeEnabled} and {@link #setThreadCpuTimeEnabled}
078 * methods can be used to test if CPU time measurement is enabled
079 * and to enable/disable this support respectively.
080 * Enabling thread CPU measurement could be expensive in some
081 * Java virtual machine implementations.
082 *
083 * <h4>Thread Contention Monitoring</h4>
084 * Some Java virtual machines may support thread contention monitoring.
085 * When thread contention monitoring is enabled, the accumulated elapsed
086 * time that the thread has blocked for synchronization or waited for
087 * notification will be collected and returned in the
088 * <a href="ThreadInfo.html#SyncStats"><tt>ThreadInfo</tt></a> object.
089 * <p>
090 * The {@link #isThreadContentionMonitoringSupported} method can be used to
091 * determine if a Java virtual machine supports thread contention monitoring.
092 * The thread contention monitoring is disabled by default. The
093 * {@link #setThreadContentionMonitoringEnabled} method can be used to enable
094 * thread contention monitoring.
095 *
096 * <h4>Synchronization Information and Deadlock Detection</h4>
097 * Some Java virtual machines may support monitoring of
098 * {@linkplain #isObjectMonitorUsageSupported object monitor usage} and
099 * {@linkplain #isSynchronizerUsageSupported ownable synchronizer usage}.
100 * The {@link #getThreadInfo(long[], boolean, boolean)} and
101 * {@link #dumpAllThreads} methods can be used to obtain the thread stack trace
102 * and synchronization information including which
103 * {@linkplain LockInfo <i>lock</i>} a thread is blocked to
104 * acquire or waiting on and which locks the thread currently owns.
105 * <p>
106 * The <tt>ThreadMXBean</tt> interface provides the
107 * {@link #findMonitorDeadlockedThreads} and
108 * {@link #findDeadlockedThreads} methods to find deadlocks in
109 * the running application.
110 *
111 * @see <a href="../../../javax/management/package-summary.html">
112 * JMX Specification.</a>
113 * @see <a href="package-summary.html#examples">
114 * Ways to Access MXBeans</a>
115 *
116 * @author Mandy Chung
117 * @version 1.26, 05/05/07
118 * @since 1.5
119 */
120
121 public interface ThreadMXBean {
122 /**
123 * Returns the current number of live threads including both
124 * daemon and non-daemon threads.
125 *
126 * @return the current number of live threads.
127 */
128 public int getThreadCount();
129
130 /**
131 * Returns the peak live thread count since the Java virtual machine
132 * started or peak was reset.
133 *
134 * @return the peak live thread count.
135 */
136 public int getPeakThreadCount();
137
138 /**
139 * Returns the total number of threads created and also started
140 * since the Java virtual machine started.
141 *
142 * @return the total number of threads started.
143 */
144 public long getTotalStartedThreadCount();
145
146 /**
147 * Returns the current number of live daemon threads.
148 *
149 * @return the current number of live daemon threads.
150 */
151 public int getDaemonThreadCount();
152
153 /**
154 * Returns all live thread IDs.
155 * Some threads included in the returned array
156 * may have been terminated when this method returns.
157 *
158 * @return an array of <tt>long</tt>, each is a thread ID.
159 *
160 * @throws java.lang.SecurityException if a security manager
161 * exists and the caller does not have
162 * ManagementPermission("monitor").
163 */
164 public long[] getAllThreadIds();
165
166 /**
167 * Returns the thread info for a thread of the specified
168 * <tt>id</tt> with no stack trace.
169 * This method is equivalent to calling:
170 * <blockquote>
171 * {@link #getThreadInfo(long, int) getThreadInfo(id, 0);}
172 * </blockquote>
173 *
174 * <p>
175 * This method returns a <tt>ThreadInfo</tt> object representing
176 * the thread information for the thread of the specified ID.
177 * The stack trace, locked monitors, and locked synchronizers
178 * in the returned <tt>ThreadInfo</tt> object will
179 * be empty.
180 *
181 * If a thread of the given ID is not alive or does not exist,
182 * this method will return <tt>null</tt>. A thread is alive if
183 * it has been started and has not yet died.
184 *
185 * <p>
186 * <b>MBeanServer access</b>:<br>
187 * The mapped type of <tt>ThreadInfo</tt> is
188 * <tt>CompositeData</tt> with attributes as specified in the
189 * {@link ThreadInfo#from ThreadInfo.from} method.
190 *
191 * @param id the thread ID of the thread. Must be positive.
192 *
193 * @return a {@link ThreadInfo} object for the thread of the given ID
194 * with no stack trace, no locked monitor and no synchronizer info;
195 * <tt>null</tt> if the thread of the given ID is not alive or
196 * it does not exist.
197 *
198 * @throws IllegalArgumentException if <tt>id <= 0</tt>.
199 * @throws java.lang.SecurityException if a security manager
200 * exists and the caller does not have
201 * ManagementPermission("monitor").
202 */
203 public ThreadInfo getThreadInfo(long id);
204
205 /**
206 * Returns the thread info for each thread
207 * whose ID is in the input array <tt>ids</tt> with no stack trace.
208 * This method is equivalent to calling:
209 * <blockquote><pre>
210 * {@link #getThreadInfo(long[], int) getThreadInfo}(ids, 0);
211 * </pre></blockquote>
212 *
213 * <p>
214 * This method returns an array of the <tt>ThreadInfo</tt> objects.
215 * The stack trace, locked monitors, and locked synchronizers
216 * in each <tt>ThreadInfo</tt> object will be empty.
217 *
218 * If a thread of a given ID is not alive or does not exist,
219 * the corresponding element in the returned array will
220 * contain <tt>null</tt>. A thread is alive if
221 * it has been started and has not yet died.
222 *
223 * <p>
224 * <b>MBeanServer access</b>:<br>
225 * The mapped type of <tt>ThreadInfo</tt> is
226 * <tt>CompositeData</tt> with attributes as specified in the
227 * {@link ThreadInfo#from ThreadInfo.from} method.
228 *
229 * @param ids an array of thread IDs.
230 * @return an array of the {@link ThreadInfo} objects, each containing
231 * information about a thread whose ID is in the corresponding
232 * element of the input array of IDs
233 * with no stack trace, no locked monitor and no synchronizer info.
234 *
235 * @throws IllegalArgumentException if any element in the input array
236 * <tt>ids</tt> is <tt><= 0</tt>.
237 * @throws java.lang.SecurityException if a security manager
238 * exists and the caller does not have
239 * ManagementPermission("monitor").
240 */
241 public ThreadInfo[] getThreadInfo(long[] ids);
242
243 /**
244 * Returns a thread info for a thread of the specified <tt>id</tt>,
245 * with stack trace of a specified number of stack trace elements.
246 * The <tt>maxDepth</tt> parameter indicates the maximum number of
247 * {@link StackTraceElement} to be retrieved from the stack trace.
248 * If <tt>maxDepth == Integer.MAX_VALUE</tt>, the entire stack trace of
249 * the thread will be dumped.
250 * If <tt>maxDepth == 0</tt>, no stack trace of the thread
251 * will be dumped.
252 * This method does not obtain the locked monitors and locked
253 * synchronizers of the thread.
254 * <p>
255 * When the Java virtual machine has no stack trace information
256 * about a thread or <tt>maxDepth == 0</tt>,
257 * the stack trace in the
258 * <tt>ThreadInfo</tt> object will be an empty array of
259 * <tt>StackTraceElement</tt>.
260 *
261 * <p>
262 * If a thread of the given ID is not alive or does not exist,
263 * this method will return <tt>null</tt>. A thread is alive if
264 * it has been started and has not yet died.
265 *
266 * <p>
267 * <b>MBeanServer access</b>:<br>
268 * The mapped type of <tt>ThreadInfo</tt> is
269 * <tt>CompositeData</tt> with attributes as specified in the
270 * {@link ThreadInfo#from ThreadInfo.from} method.
271 *
272 * @param id the thread ID of the thread. Must be positive.
273 * @param maxDepth the maximum number of entries in the stack trace
274 * to be dumped. <tt>Integer.MAX_VALUE</tt> could be used to request
275 * the entire stack to be dumped.
276 *
277 * @return a {@link ThreadInfo} of the thread of the given ID
278 * with no locked monitor and synchronizer info.
279 * <tt>null</tt> if the thread of the given ID is not alive or
280 * it does not exist.
281 *
282 * @throws IllegalArgumentException if <tt>id <= 0</tt>.
283 * @throws IllegalArgumentException if <tt>maxDepth is negative</tt>.
284 * @throws java.lang.SecurityException if a security manager
285 * exists and the caller does not have
286 * ManagementPermission("monitor").
287 *
288 */
289 public ThreadInfo getThreadInfo(long id, int maxDepth);
290
291 /**
292 * Returns the thread info for each thread
293 * whose ID is in the input array <tt>ids</tt>,
294 * with stack trace of a specified number of stack trace elements.
295 * The <tt>maxDepth</tt> parameter indicates the maximum number of
296 * {@link StackTraceElement} to be retrieved from the stack trace.
297 * If <tt>maxDepth == Integer.MAX_VALUE</tt>, the entire stack trace of
298 * the thread will be dumped.
299 * If <tt>maxDepth == 0</tt>, no stack trace of the thread
300 * will be dumped.
301 * This method does not obtain the locked monitors and locked
302 * synchronizers of the threads.
303 * <p>
304 * When the Java virtual machine has no stack trace information
305 * about a thread or <tt>maxDepth == 0</tt>,
306 * the stack trace in the
307 * <tt>ThreadInfo</tt> object will be an empty array of
308 * <tt>StackTraceElement</tt>.
309 * <p>
310 * This method returns an array of the <tt>ThreadInfo</tt> objects,
311 * each is the thread information about the thread with the same index
312 * as in the <tt>ids</tt> array.
313 * If a thread of the given ID is not alive or does not exist,
314 * <tt>null</tt> will be set in the corresponding element
315 * in the returned array. A thread is alive if
316 * it has been started and has not yet died.
317 *
318 * <p>
319 * <b>MBeanServer access</b>:<br>
320 * The mapped type of <tt>ThreadInfo</tt> is
321 * <tt>CompositeData</tt> with attributes as specified in the
322 * {@link ThreadInfo#from ThreadInfo.from} method.
323 *
324 * @param ids an array of thread IDs
325 * @param maxDepth the maximum number of entries in the stack trace
326 * to be dumped. <tt>Integer.MAX_VALUE</tt> could be used to request
327 * the entire stack to be dumped.
328 *
329 * @return an array of the {@link ThreadInfo} objects, each containing
330 * information about a thread whose ID is in the corresponding
331 * element of the input array of IDs with no locked monitor and
332 * synchronizer info.
333 *
334 * @throws IllegalArgumentException if <tt>maxDepth is negative</tt>.
335 * @throws IllegalArgumentException if any element in the input array
336 * <tt>ids</tt> is <tt><= 0</tt>.
337 * @throws java.lang.SecurityException if a security manager
338 * exists and the caller does not have
339 * ManagementPermission("monitor").
340 *
341 */
342 public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);
343
344 /**
345 * Tests if the Java virtual machine supports thread contention monitoring.
346 *
347 * @return
348 * <tt>true</tt>
349 * if the Java virtual machine supports thread contention monitoring;
350 * <tt>false</tt> otherwise.
351 */
352 public boolean isThreadContentionMonitoringSupported();
353
354 /**
355 * Tests if thread contention monitoring is enabled.
356 *
357 * @return <tt>true</tt> if thread contention monitoring is enabled;
358 * <tt>false</tt> otherwise.
359 *
360 * @throws java.lang.UnsupportedOperationException if the Java virtual
361 * machine does not support thread contention monitoring.
362 *
363 * @see #isThreadContentionMonitoringSupported
364 */
365 public boolean isThreadContentionMonitoringEnabled();
366
367 /**
368 * Enables or disables thread contention monitoring.
369 * Thread contention monitoring is disabled by default.
370 *
371 * @param enable <tt>true</tt> to enable;
372 * <tt>false</tt> to disable.
373 *
374 * @throws java.lang.UnsupportedOperationException if the Java
375 * virtual machine does not support thread contention monitoring.
376 *
377 * @throws java.lang.SecurityException if a security manager
378 * exists and the caller does not have
379 * ManagementPermission("control").
380 *
381 * @see #isThreadContentionMonitoringSupported
382 */
383 public void setThreadContentionMonitoringEnabled(boolean enable);
384
385 /**
386 * Returns the total CPU time for the current thread in nanoseconds.
387 * The returned value is of nanoseconds precision but
388 * not necessarily nanoseconds accuracy.
389 * If the implementation distinguishes between user mode time and system
390 * mode time, the returned CPU time is the amount of time that
391 * the current thread has executed in user mode or system mode.
392 *
393 * <p>
394 * This is a convenient method for local management use and is
395 * equivalent to calling:
396 * <blockquote><pre>
397 * {@link #getThreadCpuTime getThreadCpuTime}(Thread.currentThread().getId());
398 * </pre></blockquote>
399 *
400 * @return the total CPU time for the current thread if CPU time
401 * measurement is enabled; <tt>-1</tt> otherwise.
402 *
403 * @throws java.lang.UnsupportedOperationException if the Java
404 * virtual machine does not support CPU time measurement for
405 * the current thread.
406 *
407 * @see #getCurrentThreadUserTime
408 * @see #isCurrentThreadCpuTimeSupported
409 * @see #isThreadCpuTimeEnabled
410 * @see #setThreadCpuTimeEnabled
411 */
412 public long getCurrentThreadCpuTime();
413
414 /**
415 * Returns the CPU time that the current thread has executed
416 * in user mode in nanoseconds.
417 * The returned value is of nanoseconds precision but
418 * not necessarily nanoseconds accuracy.
419 *
420 * <p>
421 * This is a convenient method for local management use and is
422 * equivalent to calling:
423 * <blockquote><pre>
424 * {@link #getThreadUserTime getThreadUserTime}(Thread.currentThread().getId());
425 * </pre></blockquote>
426 *
427 * @return the user-level CPU time for the current thread if CPU time
428 * measurement is enabled; <tt>-1</tt> otherwise.
429 *
430 * @throws java.lang.UnsupportedOperationException if the Java
431 * virtual machine does not support CPU time measurement for
432 * the current thread.
433 *
434 * @see #getCurrentThreadCpuTime
435 * @see #isCurrentThreadCpuTimeSupported
436 * @see #isThreadCpuTimeEnabled
437 * @see #setThreadCpuTimeEnabled
438 */
439 public long getCurrentThreadUserTime();
440
441 /**
442 * Returns the total CPU time for a thread of the specified ID in nanoseconds.
443 * The returned value is of nanoseconds precision but
444 * not necessarily nanoseconds accuracy.
445 * If the implementation distinguishes between user mode time and system
446 * mode time, the returned CPU time is the amount of time that
447 * the thread has executed in user mode or system mode.
448 *
449 * <p>
450 * If the thread of the specified ID is not alive or does not exist,
451 * this method returns <tt>-1</tt>. If CPU time measurement
452 * is disabled, this method returns <tt>-1</tt>.
453 * A thread is alive if it has been started and has not yet died.
454 * <p>
455 * If CPU time measurement is enabled after the thread has started,
456 * the Java virtual machine implementation may choose any time up to
457 * and including the time that the capability is enabled as the point
458 * where CPU time measurement starts.
459 *
460 * @param id the thread ID of a thread
461 * @return the total CPU time for a thread of the specified ID
462 * if the thread of the specified ID exists, the thread is alive,
463 * and CPU time measurement is enabled;
464 * <tt>-1</tt> otherwise.
465 *
466 * @throws IllegalArgumentException if <tt>id <= 0 </tt>.
467 * @throws java.lang.UnsupportedOperationException if the Java
468 * virtual machine does not support CPU time measurement for
469 * other threads.
470 *
471 * @see #getThreadUserTime
472 * @see #isThreadCpuTimeSupported
473 * @see #isThreadCpuTimeEnabled
474 * @see #setThreadCpuTimeEnabled
475 */
476 public long getThreadCpuTime(long id);
477
478 /**
479 * Returns the CPU time that a thread of the specified ID
480 * has executed in user mode in nanoseconds.
481 * The returned value is of nanoseconds precision but
482 * not necessarily nanoseconds accuracy.
483 *
484 * <p>
485 * If the thread of the specified ID is not alive or does not exist,
486 * this method returns <tt>-1</tt>. If CPU time measurement
487 * is disabled, this method returns <tt>-1</tt>.
488 * A thread is alive if it has been started and has not yet died.
489 * <p>
490 * If CPU time measurement is enabled after the thread has started,
491 * the Java virtual machine implementation may choose any time up to
492 * and including the time that the capability is enabled as the point
493 * where CPU time measurement starts.
494 *
495 * @param id the thread ID of a thread
496 * @return the user-level CPU time for a thread of the specified ID
497 * if the thread of the specified ID exists, the thread is alive,
498 * and CPU time measurement is enabled;
499 * <tt>-1</tt> otherwise.
500 *
501 * @throws IllegalArgumentException if <tt>id <= 0 </tt>.
502 * @throws java.lang.UnsupportedOperationException if the Java
503 * virtual machine does not support CPU time measurement for
504 * other threads.
505 *
506 * @see #getThreadCpuTime
507 * @see #isThreadCpuTimeSupported
508 * @see #isThreadCpuTimeEnabled
509 * @see #setThreadCpuTimeEnabled
510 */
511 public long getThreadUserTime(long id);
512
513 /**
514 * Tests if the Java virtual machine implementation supports CPU time
515 * measurement for any thread.
516 * A Java virtual machine implementation that supports CPU time
517 * measurement for any thread will also support CPU time
518 * measurement for the current thread.
519 *
520 * @return
521 * <tt>true</tt>
522 * if the Java virtual machine supports CPU time
523 * measurement for any thread;
524 * <tt>false</tt> otherwise.
525 */
526 public boolean isThreadCpuTimeSupported();
527
528 /**
529 * Tests if the Java virtual machine supports CPU time
530 * measurement for the current thread.
531 * This method returns <tt>true</tt> if {@link #isThreadCpuTimeSupported}
532 * returns <tt>true</tt>.
533 *
534 * @return
535 * <tt>true</tt>
536 * if the Java virtual machine supports CPU time
537 * measurement for current thread;
538 * <tt>false</tt> otherwise.
539 */
540 public boolean isCurrentThreadCpuTimeSupported();
541
542 /**
543 * Tests if thread CPU time measurement is enabled.
544 *
545 * @return <tt>true</tt> if thread CPU time measurement is enabled;
546 * <tt>false</tt> otherwise.
547 *
548 * @throws java.lang.UnsupportedOperationException if the Java virtual
549 * machine does not support CPU time measurement for other threads
550 * nor for the current thread.
551 *
552 * @see #isThreadCpuTimeSupported
553 * @see #isCurrentThreadCpuTimeSupported
554 */
555 public boolean isThreadCpuTimeEnabled();
556
557 /**
558 * Enables or disables thread CPU time measurement. The default
559 * is platform dependent.
560 *
561 * @param enable <tt>true</tt> to enable;
562 * <tt>false</tt> to disable.
563 *
564 * @throws java.lang.UnsupportedOperationException if the Java
565 * virtual machine does not support CPU time measurement for
566 * any threads nor for the current thread.
567 *
568 * @throws java.lang.SecurityException if a security manager
569 * exists and the caller does not have
570 * ManagementPermission("control").
571 *
572 * @see #isThreadCpuTimeSupported
573 * @see #isCurrentThreadCpuTimeSupported
574 */
575 public void setThreadCpuTimeEnabled(boolean enable);
576
577 /**
578 * Finds cycles of threads that are in deadlock waiting to acquire
579 * object monitors. That is, threads that are blocked waiting to enter a
580 * synchronization block or waiting to reenter a synchronization block
581 * after an {@link Object#wait Object.wait} call,
582 * where each thread owns one monitor while
583 * trying to obtain another monitor already held by another thread
584 * in a cycle.
585 * <p>
586 * More formally, a thread is <em>monitor deadlocked</em> if it is
587 * part of a cycle in the relation "is waiting for an object monitor
588 * owned by". In the simplest case, thread A is blocked waiting
589 * for a monitor owned by thread B, and thread B is blocked waiting
590 * for a monitor owned by thread A.
591 * <p>
592 * This method is designed for troubleshooting use, but not for
593 * synchronization control. It might be an expensive operation.
594 * <p>
595 * This method finds deadlocks involving only object monitors.
596 * To find deadlocks involving both object monitors and
597 * <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>,
598 * the {@link #findDeadlockedThreads findDeadlockedThreads} method
599 * should be used.
600 *
601 * @return an array of IDs of the threads that are monitor
602 * deadlocked, if any; <tt>null</tt> otherwise.
603 *
604 * @throws java.lang.SecurityException if a security manager
605 * exists and the caller does not have
606 * ManagementPermission("monitor").
607 *
608 * @see #findDeadlockedThreads
609 */
610 public long[] findMonitorDeadlockedThreads();
611
612 /**
613 * Resets the peak thread count to the current number of
614 * live threads.
615 *
616 * @throws java.lang.SecurityException if a security manager
617 * exists and the caller does not have
618 * ManagementPermission("control").
619 *
620 * @see #getPeakThreadCount
621 * @see #getThreadCount
622 */
623 public void resetPeakThreadCount();
624
625 /**
626 * Finds cycles of threads that are in deadlock waiting to acquire
627 * object monitors or
628 * <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>.
629 *
630 * Threads are <em>deadlocked</em> in a cycle waiting for a lock of
631 * these two types if each thread owns one lock while
632 * trying to acquire another lock already held
633 * by another thread in the cycle.
634 * <p>
635 * This method is designed for troubleshooting use, but not for
636 * synchronization control. It might be an expensive operation.
637 *
638 * @return an array of IDs of the threads that are
639 * deadlocked waiting for object monitors or ownable synchronizers, if any;
640 * <tt>null</tt> otherwise.
641 *
642 * @throws java.lang.SecurityException if a security manager
643 * exists and the caller does not have
644 * ManagementPermission("monitor").
645 * @throws java.lang.UnsupportedOperationException if the Java virtual
646 * machine does not support monitoriing of ownable synchronizer usage.
647 *
648 * @see #isSynchronizerUsageSupported
649 * @see #findMonitorDeadlockedThreads
650 * @since 1.6
651 */
652 public long[] findDeadlockedThreads();
653
654 /**
655 * Tests if the Java virtual machine supports monitoring of
656 * object monitor usage.
657 *
658 * @return
659 * <tt>true</tt>
660 * if the Java virtual machine supports monitoring of
661 * object monitor usage;
662 * <tt>false</tt> otherwise.
663 *
664 * @see #dumpAllThreads
665 * @since 1.6
666 */
667 public boolean isObjectMonitorUsageSupported();
668
669 /**
670 * Tests if the Java virtual machine supports monitoring of
671 * <a href="LockInfo.html#OwnableSynchronizer">
672 * ownable synchronizer</a> usage.
673 *
674 * @return
675 * <tt>true</tt>
676 * if the Java virtual machine supports monitoring of ownable
677 * synchronizer usage;
678 * <tt>false</tt> otherwise.
679 *
680 * @see #dumpAllThreads
681 * @since 1.6
682 */
683 public boolean isSynchronizerUsageSupported();
684
685 /**
686 * Returns the thread info for each thread
687 * whose ID is in the input array <tt>ids</tt>, with stack trace
688 * and synchronization information.
689 *
690 * <p>
691 * This method obtains a snapshot of the thread information
692 * for each thread including:
693 * <ul>
694 * <li>the entire stack trace,</li>
695 * <li>the object monitors currently locked by the thread
696 * if <tt>lockedMonitors</tt> is <tt>true</tt>, and</li>
697 * <li>the <a href="LockInfo.html#OwnableSynchronizer">
698 * ownable synchronizers</a> currently locked by the thread
699 * if <tt>lockedSynchronizers</tt> is <tt>true</tt>.</li>
700 * </ul>
701 * <p>
702 * This method returns an array of the <tt>ThreadInfo</tt> objects,
703 * each is the thread information about the thread with the same index
704 * as in the <tt>ids</tt> array.
705 * If a thread of the given ID is not alive or does not exist,
706 * <tt>null</tt> will be set in the corresponding element
707 * in the returned array. A thread is alive if
708 * it has been started and has not yet died.
709 * <p>
710 * If a thread does not lock any object monitor or <tt>lockedMonitors</tt>
711 * is <tt>false</tt>, the returned <tt>ThreadInfo</tt> object will have an
712 * empty <tt>MonitorInfo</tt> array. Similarly, if a thread does not
713 * lock any synchronizer or <tt>lockedSynchronizers</tt> is <tt>false</tt>,
714 * the returned <tt>ThreadInfo</tt> object
715 * will have an empty <tt>LockInfo</tt> array.
716 *
717 * <p>
718 * When both <tt>lockedMonitors</tt> and <tt>lockedSynchronizers</tt>
719 * parameters are <tt>false</tt>, it is equivalent to calling:
720 * <blockquote><pre>
721 * {@link #getThreadInfo(long[], int) getThreadInfo(ids, Integer.MAX_VALUE)}
722 * </pre></blockquote>
723 *
724 * <p>
725 * This method is designed for troubleshooting use, but not for
726 * synchronization control. It might be an expensive operation.
727 *
728 * <p>
729 * <b>MBeanServer access</b>:<br>
730 * The mapped type of <tt>ThreadInfo</tt> is
731 * <tt>CompositeData</tt> with attributes as specified in the
732 * {@link ThreadInfo#from ThreadInfo.from} method.
733 *
734 * @param ids an array of thread IDs.
735 * @param lockedMonitors if <tt>true</tt>, retrieves all locked monitors.
736 * @param lockedSynchronizers if <tt>true</tt>, retrieves all locked
737 * ownable synchronizers.
738 *
739 * @return an array of the {@link ThreadInfo} objects, each containing
740 * information about a thread whose ID is in the corresponding
741 * element of the input array of IDs.
742 *
743 * @throws java.lang.SecurityException if a security manager
744 * exists and the caller does not have
745 * ManagementPermission("monitor").
746 * @throws java.lang.UnsupportedOperationException
747 * <ul>
748 * <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
749 * the Java virtual machine does not support monitoring
750 * of {@linkplain #isObjectMonitorUsageSupported
751 * object monitor usage}; or</li>
752 * <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
753 * the Java virtual machine does not support monitoring
754 * of {@linkplain #isSynchronizerUsageSupported
755 * ownable synchronizer usage}.</li>
756 * </ul>
757 *
758 * @see #isObjectMonitorUsageSupported
759 * @see #isSynchronizerUsageSupported
760 *
761 * @since 1.6
762 */
763 public ThreadInfo[] getThreadInfo(long[] ids,
764 boolean lockedMonitors, boolean lockedSynchronizers);
765
766 /**
767 * Returns the thread info for all live threads with stack trace
768 * and synchronization information.
769 * Some threads included in the returned array
770 * may have been terminated when this method returns.
771 *
772 * <p>
773 * This method returns an array of {@link ThreadInfo} objects
774 * as specified in the {@link #getThreadInfo(long[], boolean, boolean)}
775 * method.
776 *
777 * @param lockedMonitors if <tt>true</tt>, dump all locked monitors.
778 * @param lockedSynchronizers if <tt>true</tt>, dump all locked
779 * ownable synchronizers.
780 *
781 * @return an array of {@link ThreadInfo} for all live threads.
782 *
783 * @throws java.lang.SecurityException if a security manager
784 * exists and the caller does not have
785 * ManagementPermission("monitor").
786 * @throws java.lang.UnsupportedOperationException
787 * <ul>
788 * <li>if <tt>lockedMonitors</tt> is <tt>true</tt> but
789 * the Java virtual machine does not support monitoring
790 * of {@linkplain #isObjectMonitorUsageSupported
791 * object monitor usage}; or</li>
792 * <li>if <tt>lockedSynchronizers</tt> is <tt>true</tt> but
793 * the Java virtual machine does not support monitoring
794 * of {@linkplain #isSynchronizerUsageSupported
795 * ownable synchronizer usage}.</li>
796 * </ul>
797 *
798 * @see #isObjectMonitorUsageSupported
799 * @see #isSynchronizerUsageSupported
800 *
801 * @since 1.6
802 */
803 public ThreadInfo[] dumpAllThreads(boolean lockedMonitors,
804 boolean lockedSynchronizers);
805 }
|