Path: blob/master/src/java.management/share/classes/java/lang/management/ThreadMXBean.java
41159 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.lang.management;2627import java.util.Map;2829/**30* The management interface for the thread system of31* the Java virtual machine.32*33* <p> A Java virtual machine has a single instance of the implementation34* class of this interface. This instance implementing this interface is35* an <a href="ManagementFactory.html#MXBean">MXBean</a>36* that can be obtained by calling37* the {@link ManagementFactory#getThreadMXBean} method or38* from the {@link ManagementFactory#getPlatformMBeanServer39* platform MBeanServer} method.40*41* <p>The {@code ObjectName} for uniquely identifying the MXBean for42* the thread system within an MBeanServer is:43* <blockquote>44* {@link ManagementFactory#THREAD_MXBEAN_NAME45* java.lang:type=Threading}46* </blockquote>47*48* It can be obtained by calling the49* {@link PlatformManagedObject#getObjectName} method.50*51* <h2>Thread ID</h2>52* Thread ID is a positive long value returned by calling the53* {@link java.lang.Thread#getId} method for a thread.54* The thread ID is unique during its lifetime. When a thread55* is terminated, this thread ID may be reused.56*57* <p> Some methods in this interface take a thread ID or an array58* of thread IDs as the input parameter and return per-thread information.59*60* <h2>Thread CPU time</h2>61* A Java virtual machine implementation may support measuring62* the CPU time for the current thread, for any thread, or for no threads.63*64* <p>65* The {@link #isThreadCpuTimeSupported} method can be used to determine66* if a Java virtual machine supports measuring of the CPU time for any67* thread. The {@link #isCurrentThreadCpuTimeSupported} method can68* be used to determine if a Java virtual machine supports measuring of69* the CPU time for the current thread.70* A Java virtual machine implementation that supports CPU time measurement71* for any thread will also support that for the current thread.72*73* <p> The CPU time provided by this interface has nanosecond precision74* but not necessarily nanosecond accuracy.75*76* <p>77* A Java virtual machine may disable CPU time measurement78* by default.79* The {@link #isThreadCpuTimeEnabled} and {@link #setThreadCpuTimeEnabled}80* methods can be used to test if CPU time measurement is enabled81* and to enable/disable this support respectively.82* Enabling thread CPU measurement could be expensive in some83* Java virtual machine implementations.84*85* <h2>Thread Contention Monitoring</h2>86* Some Java virtual machines may support thread contention monitoring.87* When thread contention monitoring is enabled, the accumulated elapsed88* time that the thread has blocked for synchronization or waited for89* notification will be collected and returned in the90* <a href="ThreadInfo.html#SyncStats">{@code ThreadInfo}</a> object.91* <p>92* The {@link #isThreadContentionMonitoringSupported} method can be used to93* determine if a Java virtual machine supports thread contention monitoring.94* The thread contention monitoring is disabled by default. The95* {@link #setThreadContentionMonitoringEnabled} method can be used to enable96* thread contention monitoring.97*98* <h2>Synchronization Information and Deadlock Detection</h2>99* Some Java virtual machines may support monitoring of100* {@linkplain #isObjectMonitorUsageSupported object monitor usage} and101* {@linkplain #isSynchronizerUsageSupported ownable synchronizer usage}.102* The {@link #getThreadInfo(long[], boolean, boolean)} and103* {@link #dumpAllThreads} methods can be used to obtain the thread stack trace104* and synchronization information including which105* {@linkplain LockInfo <i>lock</i>} a thread is blocked to106* acquire or waiting on and which locks the thread currently owns.107* <p>108* The {@code ThreadMXBean} interface provides the109* {@link #findMonitorDeadlockedThreads} and110* {@link #findDeadlockedThreads} methods to find deadlocks in111* the running application.112*113* @see ManagementFactory#getPlatformMXBeans(Class)114* @see <a href="../../../javax/management/package-summary.html">115* JMX Specification.</a>116* @see <a href="package-summary.html#examples">117* Ways to Access MXBeans</a>118*119* @author Mandy Chung120* @since 1.5121*/122123public interface ThreadMXBean extends PlatformManagedObject {124/**125* Returns the current number of live threads including both126* daemon and non-daemon threads.127*128* @return the current number of live threads.129*/130public int getThreadCount();131132/**133* Returns the peak live thread count since the Java virtual machine134* started or peak was reset.135*136* @return the peak live thread count.137*/138public int getPeakThreadCount();139140/**141* Returns the total number of threads created and also started142* since the Java virtual machine started.143*144* @return the total number of threads started.145*/146public long getTotalStartedThreadCount();147148/**149* Returns the current number of live daemon threads.150*151* @return the current number of live daemon threads.152*/153public int getDaemonThreadCount();154155/**156* Returns all live thread IDs.157* Some threads included in the returned array158* may have been terminated when this method returns.159*160* @return an array of {@code long}, each is a thread ID.161*162* @throws SecurityException if a security manager163* exists and the caller does not have164* ManagementPermission("monitor").165*/166public long[] getAllThreadIds();167168/**169* Returns the thread info for a thread of the specified170* {@code id} with no stack trace.171* This method is equivalent to calling:172* <blockquote>173* {@link #getThreadInfo(long, int) getThreadInfo(id, 0);}174* </blockquote>175*176* <p>177* This method returns a {@code ThreadInfo} object representing178* the thread information for the thread of the specified ID.179* The stack trace, locked monitors, and locked synchronizers180* in the returned {@code ThreadInfo} object will181* be empty.182*183* If a thread of the given ID is not alive or does not exist,184* this method will return {@code null}. A thread is alive if185* it has been started and has not yet died.186*187* <p>188* <b>MBeanServer access</b>:<br>189* The mapped type of {@code ThreadInfo} is190* {@code CompositeData} with attributes as specified in the191* {@link ThreadInfo#from ThreadInfo.from} method.192*193* @param id the thread ID of the thread. Must be positive.194*195* @return a {@link ThreadInfo} object for the thread of the given ID196* with no stack trace, no locked monitor and no synchronizer info;197* {@code null} if the thread of the given ID is not alive or198* it does not exist.199*200* @throws IllegalArgumentException if {@code id <= 0}.201* @throws SecurityException if a security manager202* exists and the caller does not have203* ManagementPermission("monitor").204*/205public ThreadInfo getThreadInfo(long id);206207/**208* Returns the thread info for each thread209* whose ID is in the input array {@code ids} with no stack trace.210* This method is equivalent to calling:211* <blockquote><pre>212* {@link #getThreadInfo(long[], int) getThreadInfo}(ids, 0);213* </pre></blockquote>214*215* <p>216* This method returns an array of the {@code ThreadInfo} objects.217* The stack trace, locked monitors, and locked synchronizers218* in each {@code ThreadInfo} object will be empty.219*220* If a thread of a given ID is not alive or does not exist,221* the corresponding element in the returned array will222* contain {@code null}. A thread is alive if223* it has been started and has not yet died.224*225* <p>226* <b>MBeanServer access</b>:<br>227* The mapped type of {@code ThreadInfo} is228* {@code CompositeData} with attributes as specified in the229* {@link ThreadInfo#from ThreadInfo.from} method.230*231* @param ids an array of thread IDs.232* @return an array of the {@link ThreadInfo} objects, each containing233* information about a thread whose ID is in the corresponding234* element of the input array of IDs235* with no stack trace, no locked monitor and no synchronizer info.236*237* @throws IllegalArgumentException if any element in the input array238* {@code ids} is {@code <= 0}.239* @throws SecurityException if a security manager240* exists and the caller does not have241* ManagementPermission("monitor").242*/243public ThreadInfo[] getThreadInfo(long[] ids);244245/**246* Returns a thread info for a thread of the specified {@code id},247* with stack trace of a specified number of stack trace elements.248* The {@code maxDepth} parameter indicates the maximum number of249* {@link StackTraceElement} to be retrieved from the stack trace.250* If {@code maxDepth == Integer.MAX_VALUE}, the entire stack trace of251* the thread will be dumped.252* If {@code maxDepth == 0}, no stack trace of the thread253* will be dumped.254* This method does not obtain the locked monitors and locked255* synchronizers of the thread.256* <p>257* When the Java virtual machine has no stack trace information258* about a thread or {@code maxDepth == 0},259* the stack trace in the260* {@code ThreadInfo} object will be an empty array of261* {@code StackTraceElement}.262*263* <p>264* If a thread of the given ID is not alive or does not exist,265* this method will return {@code null}. A thread is alive if266* it has been started and has not yet died.267*268* <p>269* <b>MBeanServer access</b>:<br>270* The mapped type of {@code ThreadInfo} is271* {@code CompositeData} with attributes as specified in the272* {@link ThreadInfo#from ThreadInfo.from} method.273*274* @param id the thread ID of the thread. Must be positive.275* @param maxDepth the maximum number of entries in the stack trace276* to be dumped. {@code Integer.MAX_VALUE} could be used to request277* the entire stack to be dumped.278*279* @return a {@link ThreadInfo} of the thread of the given ID280* with no locked monitor and synchronizer info.281* {@code null} if the thread of the given ID is not alive or282* it does not exist.283*284* @throws IllegalArgumentException if {@code id <= 0}.285* @throws IllegalArgumentException if {@code maxDepth is negative}.286* @throws SecurityException if a security manager287* exists and the caller does not have288* ManagementPermission("monitor").289*290*/291public ThreadInfo getThreadInfo(long id, int maxDepth);292293/**294* Returns the thread info for each thread295* whose ID is in the input array {@code ids},296* with stack trace of a specified number of stack trace elements.297* The {@code maxDepth} parameter indicates the maximum number of298* {@link StackTraceElement} to be retrieved from the stack trace.299* If {@code maxDepth == Integer.MAX_VALUE}, the entire stack trace of300* the thread will be dumped.301* If {@code maxDepth == 0}, no stack trace of the thread302* will be dumped.303* This method does not obtain the locked monitors and locked304* synchronizers of the threads.305* <p>306* When the Java virtual machine has no stack trace information307* about a thread or {@code maxDepth == 0},308* the stack trace in the309* {@code ThreadInfo} object will be an empty array of310* {@code StackTraceElement}.311* <p>312* This method returns an array of the {@code ThreadInfo} objects,313* each is the thread information about the thread with the same index314* as in the {@code ids} array.315* If a thread of the given ID is not alive or does not exist,316* {@code null} will be set in the corresponding element317* in the returned array. A thread is alive if318* it has been started and has not yet died.319*320* <p>321* <b>MBeanServer access</b>:<br>322* The mapped type of {@code ThreadInfo} is323* {@code CompositeData} with attributes as specified in the324* {@link ThreadInfo#from ThreadInfo.from} method.325*326* @param ids an array of thread IDs327* @param maxDepth the maximum number of entries in the stack trace328* to be dumped. {@code Integer.MAX_VALUE} could be used to request329* the entire stack to be dumped.330*331* @return an array of the {@link ThreadInfo} objects, each containing332* information about a thread whose ID is in the corresponding333* element of the input array of IDs with no locked monitor and334* synchronizer info.335*336* @throws IllegalArgumentException if {@code maxDepth is negative}.337* @throws IllegalArgumentException if any element in the input array338* {@code ids} is {@code <= 0}.339* @throws SecurityException if a security manager340* exists and the caller does not have341* ManagementPermission("monitor").342*343*/344public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);345346/**347* Tests if the Java virtual machine supports thread contention monitoring.348*349* @return350* {@code true}351* if the Java virtual machine supports thread contention monitoring;352* {@code false} otherwise.353*/354public boolean isThreadContentionMonitoringSupported();355356/**357* Tests if thread contention monitoring is enabled.358*359* @return {@code true} if thread contention monitoring is enabled;360* {@code false} otherwise.361*362* @throws UnsupportedOperationException if the Java virtual363* machine does not support thread contention monitoring.364*365* @see #isThreadContentionMonitoringSupported366*/367public boolean isThreadContentionMonitoringEnabled();368369/**370* Enables or disables thread contention monitoring.371* Thread contention monitoring is disabled by default.372*373* @param enable {@code true} to enable;374* {@code false} to disable.375*376* @throws UnsupportedOperationException if the Java377* virtual machine does not support thread contention monitoring.378*379* @throws SecurityException if a security manager380* exists and the caller does not have381* ManagementPermission("control").382*383* @see #isThreadContentionMonitoringSupported384*/385public void setThreadContentionMonitoringEnabled(boolean enable);386387/**388* Returns the total CPU time for the current thread in nanoseconds.389* The returned value is of nanoseconds precision but390* not necessarily nanoseconds accuracy.391* If the implementation distinguishes between user mode time and system392* mode time, the returned CPU time is the amount of time that393* the current thread has executed in user mode or system mode.394*395* <p>396* This is a convenience method for local management use and is397* equivalent to calling:398* <blockquote><pre>399* {@link #getThreadCpuTime getThreadCpuTime}(Thread.currentThread().getId());400* </pre></blockquote>401*402* @return the total CPU time for the current thread if CPU time403* measurement is enabled; {@code -1} otherwise.404*405* @throws UnsupportedOperationException if the Java406* virtual machine does not support CPU time measurement for407* the current thread.408*409* @see #getCurrentThreadUserTime410* @see #isCurrentThreadCpuTimeSupported411* @see #isThreadCpuTimeEnabled412* @see #setThreadCpuTimeEnabled413*/414public long getCurrentThreadCpuTime();415416/**417* Returns the CPU time that the current thread has executed418* in user mode in nanoseconds.419* The returned value is of nanoseconds precision but420* not necessarily nanoseconds accuracy.421*422* <p>423* This is a convenience method for local management use and is424* equivalent to calling:425* <blockquote><pre>426* {@link #getThreadUserTime getThreadUserTime}(Thread.currentThread().getId());427* </pre></blockquote>428*429* @return the user-level CPU time for the current thread if CPU time430* measurement is enabled; {@code -1} otherwise.431*432* @throws UnsupportedOperationException if the Java433* virtual machine does not support CPU time measurement for434* the current thread.435*436* @see #getCurrentThreadCpuTime437* @see #isCurrentThreadCpuTimeSupported438* @see #isThreadCpuTimeEnabled439* @see #setThreadCpuTimeEnabled440*/441public long getCurrentThreadUserTime();442443/**444* Returns the total CPU time for a thread of the specified ID in nanoseconds.445* The returned value is of nanoseconds precision but446* not necessarily nanoseconds accuracy.447* If the implementation distinguishes between user mode time and system448* mode time, the returned CPU time is the amount of time that449* the thread has executed in user mode or system mode.450*451* <p>452* If the thread of the specified ID is not alive or does not exist,453* this method returns {@code -1}. If CPU time measurement454* is disabled, this method returns {@code -1}.455* A thread is alive if it has been started and has not yet died.456* <p>457* If CPU time measurement is enabled after the thread has started,458* the Java virtual machine implementation may choose any time up to459* and including the time that the capability is enabled as the point460* where CPU time measurement starts.461*462* @param id the thread ID of a thread463* @return the total CPU time for a thread of the specified ID464* if the thread of the specified ID exists, the thread is alive,465* and CPU time measurement is enabled;466* {@code -1} otherwise.467*468* @throws IllegalArgumentException if {@code id <= 0}.469* @throws UnsupportedOperationException if the Java470* virtual machine does not support CPU time measurement for471* other threads.472*473* @see #getThreadUserTime474* @see #isThreadCpuTimeSupported475* @see #isThreadCpuTimeEnabled476* @see #setThreadCpuTimeEnabled477*/478public long getThreadCpuTime(long id);479480/**481* Returns the CPU time that a thread of the specified ID482* has executed in user mode in nanoseconds.483* The returned value is of nanoseconds precision but484* not necessarily nanoseconds accuracy.485*486* <p>487* If the thread of the specified ID is not alive or does not exist,488* this method returns {@code -1}. If CPU time measurement489* is disabled, this method returns {@code -1}.490* A thread is alive if it has been started and has not yet died.491* <p>492* If CPU time measurement is enabled after the thread has started,493* the Java virtual machine implementation may choose any time up to494* and including the time that the capability is enabled as the point495* where CPU time measurement starts.496*497* @param id the thread ID of a thread498* @return the user-level CPU time for a thread of the specified ID499* if the thread of the specified ID exists, the thread is alive,500* and CPU time measurement is enabled;501* {@code -1} otherwise.502*503* @throws IllegalArgumentException if {@code id <= 0}.504* @throws UnsupportedOperationException if the Java505* virtual machine does not support CPU time measurement for506* other threads.507*508* @see #getThreadCpuTime509* @see #isThreadCpuTimeSupported510* @see #isThreadCpuTimeEnabled511* @see #setThreadCpuTimeEnabled512*/513public long getThreadUserTime(long id);514515/**516* Tests if the Java virtual machine implementation supports CPU time517* measurement for any thread.518* A Java virtual machine implementation that supports CPU time519* measurement for any thread will also support CPU time520* measurement for the current thread.521*522* @return523* {@code true}524* if the Java virtual machine supports CPU time525* measurement for any thread;526* {@code false} otherwise.527*/528public boolean isThreadCpuTimeSupported();529530/**531* Tests if the Java virtual machine supports CPU time532* measurement for the current thread.533* This method returns {@code true} if {@link #isThreadCpuTimeSupported}534* returns {@code true}.535*536* @return537* {@code true}538* if the Java virtual machine supports CPU time539* measurement for current thread;540* {@code false} otherwise.541*/542public boolean isCurrentThreadCpuTimeSupported();543544/**545* Tests if thread CPU time measurement is enabled.546*547* @return {@code true} if thread CPU time measurement is enabled;548* {@code false} otherwise.549*550* @throws UnsupportedOperationException if the Java virtual551* machine does not support CPU time measurement for other threads552* nor for the current thread.553*554* @see #isThreadCpuTimeSupported555* @see #isCurrentThreadCpuTimeSupported556*/557public boolean isThreadCpuTimeEnabled();558559/**560* Enables or disables thread CPU time measurement. The default561* is platform dependent.562*563* @param enable {@code true} to enable;564* {@code false} to disable.565*566* @throws UnsupportedOperationException if the Java567* virtual machine does not support CPU time measurement for568* any threads nor for the current thread.569*570* @throws SecurityException if a security manager571* exists and the caller does not have572* ManagementPermission("control").573*574* @see #isThreadCpuTimeSupported575* @see #isCurrentThreadCpuTimeSupported576*/577public void setThreadCpuTimeEnabled(boolean enable);578579/**580* Finds cycles of threads that are in deadlock waiting to acquire581* object monitors. That is, threads that are blocked waiting to enter a582* synchronization block or waiting to reenter a synchronization block583* after an {@link Object#wait Object.wait} call,584* where each thread owns one monitor while585* trying to obtain another monitor already held by another thread586* in a cycle.587* <p>588* More formally, a thread is <em>monitor deadlocked</em> if it is589* part of a cycle in the relation "is waiting for an object monitor590* owned by". In the simplest case, thread A is blocked waiting591* for a monitor owned by thread B, and thread B is blocked waiting592* for a monitor owned by thread A.593* <p>594* This method is designed for troubleshooting use, but not for595* synchronization control. It might be an expensive operation.596* <p>597* This method finds deadlocks involving only object monitors.598* To find deadlocks involving both object monitors and599* <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>,600* the {@link #findDeadlockedThreads findDeadlockedThreads} method601* should be used.602*603* @return an array of IDs of the threads that are monitor604* deadlocked, if any; {@code null} otherwise.605*606* @throws SecurityException if a security manager607* exists and the caller does not have608* ManagementPermission("monitor").609*610* @see #findDeadlockedThreads611*/612public long[] findMonitorDeadlockedThreads();613614/**615* Resets the peak thread count to the current number of616* live threads.617*618* @throws SecurityException if a security manager619* exists and the caller does not have620* ManagementPermission("control").621*622* @see #getPeakThreadCount623* @see #getThreadCount624*/625public void resetPeakThreadCount();626627/**628* Finds cycles of threads that are in deadlock waiting to acquire629* object monitors or630* <a href="LockInfo.html#OwnableSynchronizer">ownable synchronizers</a>.631*632* Threads are <em>deadlocked</em> in a cycle waiting for a lock of633* these two types if each thread owns one lock while634* trying to acquire another lock already held635* by another thread in the cycle.636* <p>637* This method is designed for troubleshooting use, but not for638* synchronization control. It might be an expensive operation.639*640* @return an array of IDs of the threads that are641* deadlocked waiting for object monitors or ownable synchronizers, if any;642* {@code null} otherwise.643*644* @throws SecurityException if a security manager645* exists and the caller does not have646* ManagementPermission("monitor").647* @throws UnsupportedOperationException if the Java virtual648* machine does not support monitoring of ownable synchronizer usage.649*650* @see #isSynchronizerUsageSupported651* @see #findMonitorDeadlockedThreads652* @since 1.6653*/654public long[] findDeadlockedThreads();655656/**657* Tests if the Java virtual machine supports monitoring of658* object monitor usage.659*660* @return661* {@code true}662* if the Java virtual machine supports monitoring of663* object monitor usage;664* {@code false} otherwise.665*666* @see #dumpAllThreads667* @since 1.6668*/669public boolean isObjectMonitorUsageSupported();670671/**672* Tests if the Java virtual machine supports monitoring of673* <a href="LockInfo.html#OwnableSynchronizer">674* ownable synchronizer</a> usage.675*676* @return677* {@code true}678* if the Java virtual machine supports monitoring of ownable679* synchronizer usage;680* {@code false} otherwise.681*682* @see #dumpAllThreads683* @since 1.6684*/685public boolean isSynchronizerUsageSupported();686687/**688* Returns the thread info for each thread689* whose ID is in the input array {@code ids},690* with stack trace and synchronization information.691* This is equivalent to calling:692* <blockquote>693* {@link #getThreadInfo(long[], boolean, boolean, int)694* getThreadInfo(ids, lockedMonitors, lockedSynchronizers, Integer.MAX_VALUE)}695* </blockquote>696*697* @param ids an array of thread IDs.698* @param lockedMonitors if {@code true}, retrieves all locked monitors.699* @param lockedSynchronizers if {@code true}, retrieves all locked700* ownable synchronizers.701*702* @return an array of the {@link ThreadInfo} objects, each containing703* information about a thread whose ID is in the corresponding704* element of the input array of IDs.705*706* @throws SecurityException if a security manager707* exists and the caller does not have708* ManagementPermission("monitor").709* @throws UnsupportedOperationException710* <ul>711* <li>if {@code lockedMonitors} is {@code true} but712* the Java virtual machine does not support monitoring713* of {@linkplain #isObjectMonitorUsageSupported714* object monitor usage}; or</li>715* <li>if {@code lockedSynchronizers} is {@code true} but716* the Java virtual machine does not support monitoring717* of {@linkplain #isSynchronizerUsageSupported718* ownable synchronizer usage}.</li>719* </ul>720*721* @see #isObjectMonitorUsageSupported722* @see #isSynchronizerUsageSupported723*724* @since 1.6725*/726public ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,727boolean lockedSynchronizers);728729/**730* Returns the thread info for each thread whose ID731* is in the input array {@code ids},732* with stack trace of the specified maximum number of elements733* and synchronization information.734* If {@code maxDepth == 0}, no stack trace of the thread735* will be dumped.736*737* <p>738* This method obtains a snapshot of the thread information739* for each thread including:740* <ul>741* <li>stack trace of the specified maximum number of elements,</li>742* <li>the object monitors currently locked by the thread743* if {@code lockedMonitors} is {@code true}, and</li>744* <li>the <a href="LockInfo.html#OwnableSynchronizer">745* ownable synchronizers</a> currently locked by the thread746* if {@code lockedSynchronizers} is {@code true}.</li>747* </ul>748* <p>749* This method returns an array of the {@code ThreadInfo} objects,750* each is the thread information about the thread with the same index751* as in the {@code ids} array.752* If a thread of the given ID is not alive or does not exist,753* {@code null} will be set in the corresponding element754* in the returned array. A thread is alive if755* it has been started and has not yet died.756* <p>757* If a thread does not lock any object monitor or {@code lockedMonitors}758* is {@code false}, the returned {@code ThreadInfo} object will have an759* empty {@code MonitorInfo} array. Similarly, if a thread does not760* lock any synchronizer or {@code lockedSynchronizers} is {@code false},761* the returned {@code ThreadInfo} object762* will have an empty {@code LockInfo} array.763*764* <p>765* When both {@code lockedMonitors} and {@code lockedSynchronizers}766* parameters are {@code false}, it is equivalent to calling:767* <blockquote><pre>768* {@link #getThreadInfo(long[], int) getThreadInfo(ids, maxDepth)}769* </pre></blockquote>770*771* <p>772* This method is designed for troubleshooting use, but not for773* synchronization control. It might be an expensive operation.774*775* <p>776* <b>MBeanServer access</b>:<br>777* The mapped type of {@code ThreadInfo} is778* {@code CompositeData} with attributes as specified in the779* {@link ThreadInfo#from ThreadInfo.from} method.780*781* @implSpec The default implementation throws782* {@code UnsupportedOperationException}.783*784* @param ids an array of thread IDs.785* @param lockedMonitors if {@code true}, retrieves all locked monitors.786* @param lockedSynchronizers if {@code true}, retrieves all locked787* ownable synchronizers.788* @param maxDepth indicates the maximum number of789* {@link StackTraceElement} to be retrieved from the stack trace.790*791* @return an array of the {@link ThreadInfo} objects, each containing792* information about a thread whose ID is in the corresponding793* element of the input array of IDs.794*795* @throws IllegalArgumentException if {@code maxDepth} is negative.796* @throws SecurityException if a security manager797* exists and the caller does not have798* ManagementPermission("monitor").799* @throws UnsupportedOperationException800* <ul>801* <li>if {@code lockedMonitors} is {@code true} but802* the Java virtual machine does not support monitoring803* of {@linkplain #isObjectMonitorUsageSupported804* object monitor usage}; or</li>805* <li>if {@code lockedSynchronizers} is {@code true} but806* the Java virtual machine does not support monitoring807* of {@linkplain #isSynchronizerUsageSupported808* ownable synchronizer usage}.</li>809* </ul>810*811* @see #isObjectMonitorUsageSupported812* @see #isSynchronizerUsageSupported813*814* @since 10815*/816817public default ThreadInfo[] getThreadInfo(long[] ids, boolean lockedMonitors,818boolean lockedSynchronizers, int maxDepth) {819throw new UnsupportedOperationException();820}821822/**823* Returns the thread info for all live threads with stack trace824* and synchronization information.825* This is equivalent to calling:826* <blockquote>827* {@link #dumpAllThreads(boolean, boolean, int)828* dumpAllThreads(lockedMonitors, lockedSynchronizers, Integer.MAX_VALUE)}829* </blockquote>830*831* @param lockedMonitors if {@code true}, dump all locked monitors.832* @param lockedSynchronizers if {@code true}, dump all locked833* ownable synchronizers.834*835* @return an array of {@link ThreadInfo} for all live threads.836*837* @throws SecurityException if a security manager838* exists and the caller does not have839* ManagementPermission("monitor").840* @throws UnsupportedOperationException841* <ul>842* <li>if {@code lockedMonitors} is {@code true} but843* the Java virtual machine does not support monitoring844* of {@linkplain #isObjectMonitorUsageSupported845* object monitor usage}; or</li>846* <li>if {@code lockedSynchronizers} is {@code true} but847* the Java virtual machine does not support monitoring848* of {@linkplain #isSynchronizerUsageSupported849* ownable synchronizer usage}.</li>850* </ul>851*852* @see #isObjectMonitorUsageSupported853* @see #isSynchronizerUsageSupported854*855* @since 1.6856*/857public ThreadInfo[] dumpAllThreads(boolean lockedMonitors, boolean lockedSynchronizers);858859860/**861* Returns the thread info for all live threads862* with stack trace of the specified maximum number of elements863* and synchronization information.864* if {@code maxDepth == 0}, no stack trace of the thread865* will be dumped.866* Some threads included in the returned array867* may have been terminated when this method returns.868*869* <p>870* This method returns an array of {@link ThreadInfo} objects871* as specified in the {@link #getThreadInfo(long[], boolean, boolean, int)}872* method.873*874* @implSpec The default implementation throws875* {@code UnsupportedOperationException}.876*877* @param lockedMonitors if {@code true}, dump all locked monitors.878* @param lockedSynchronizers if {@code true}, dump all locked879* ownable synchronizers.880* @param maxDepth indicates the maximum number of881* {@link StackTraceElement} to be retrieved from the stack trace.882*883* @return an array of {@link ThreadInfo} for all live threads.884*885* @throws IllegalArgumentException if {@code maxDepth} is negative.886* @throws SecurityException if a security manager887* exists and the caller does not have888* ManagementPermission("monitor").889* @throws UnsupportedOperationException890* <ul>891* <li>if {@code lockedMonitors} is {@code true} but892* the Java virtual machine does not support monitoring893* of {@linkplain #isObjectMonitorUsageSupported894* object monitor usage}; or</li>895* <li>if {@code lockedSynchronizers} is {@code true} but896* the Java virtual machine does not support monitoring897* of {@linkplain #isSynchronizerUsageSupported898* ownable synchronizer usage}.</li>899* </ul>900*901* @see #isObjectMonitorUsageSupported902* @see #isSynchronizerUsageSupported903*904* @since 10905*/906public default ThreadInfo[] dumpAllThreads(boolean lockedMonitors,907boolean lockedSynchronizers, int maxDepth) {908throw new UnsupportedOperationException();909}910}911912913