1 *java.lang.management.ThreadMXBean* *ThreadMXBean* The management interface for
3 public interface interface ThreadMXBean
6 |java.lang.management.ThreadMXBean_Description|
7 |java.lang.management.ThreadMXBean_Fields|
8 |java.lang.management.ThreadMXBean_Constructors|
9 |java.lang.management.ThreadMXBean_Methods|
11 ================================================================================
13 *java.lang.management.ThreadMXBean_Methods*
14 |java.lang.management.ThreadMXBean.findMonitorDeadlockedThreads()|Finds cycles
15 |java.lang.management.ThreadMXBean.getAllThreadIds()|Returns all live thread ID
16 |java.lang.management.ThreadMXBean.getCurrentThreadCpuTime()|Returns the total
17 |java.lang.management.ThreadMXBean.getCurrentThreadUserTime()|Returns the CPU t
18 |java.lang.management.ThreadMXBean.getDaemonThreadCount()|Returns the current n
19 |java.lang.management.ThreadMXBean.getPeakThreadCount()|Returns the peak live t
20 |java.lang.management.ThreadMXBean.getThreadCount()|Returns the current number
21 |java.lang.management.ThreadMXBean.getThreadCpuTime(long)|Returns the total CPU
22 |java.lang.management.ThreadMXBean.getThreadInfo(long)|Returns the thread info
23 |java.lang.management.ThreadMXBean.getThreadInfo(long[])|Returns the thread inf
24 |java.lang.management.ThreadMXBean.getThreadInfo(long[],int)|Returns the thread
25 |java.lang.management.ThreadMXBean.getThreadInfo(long,int)|Returns a thread inf
26 |java.lang.management.ThreadMXBean.getThreadUserTime(long)|Returns the CPU time
27 |java.lang.management.ThreadMXBean.getTotalStartedThreadCount()|Returns the tot
28 |java.lang.management.ThreadMXBean.isCurrentThreadCpuTimeSupported()|Tests if t
29 |java.lang.management.ThreadMXBean.isThreadContentionMonitoringEnabled()|Tests
30 |java.lang.management.ThreadMXBean.isThreadContentionMonitoringSupported()|Test
31 |java.lang.management.ThreadMXBean.isThreadCpuTimeEnabled()|Tests if thread CPU
32 |java.lang.management.ThreadMXBean.isThreadCpuTimeSupported()|Tests if the Java
33 |java.lang.management.ThreadMXBean.resetPeakThreadCount()|Resets the peak threa
34 |java.lang.management.ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)|
35 |java.lang.management.ThreadMXBean.setThreadCpuTimeEnabled(boolean)|Enables or
37 *java.lang.management.ThreadMXBean_Description*
39 The management interface for the thread system of the Java virtual machine.
41 A Java virtual machine has a single instance of the implementation class of
42 this interface. This instance implementing this interface is an MXBean that can
43 be obtained by calling the (|java.lang.management.ManagementFactory|) method or
45 <tt>MBeanServer</tt>(|java.lang.management.ManagementFactory|) method.
47 The ObjectName for uniquely identifying the MXBean for the thread system within
49 <tt>java.lang:type=Threading</tt>(|java.lang.management.ManagementFactory|)
51 Thread ID Thread ID is a positive long value returned by calling the
52 (|java.lang.Thread|) method for a thread. The thread ID is unique during its
53 lifetime. When a thread is terminated, this thread ID may be reused.
55 Some methods in this interface take a thread ID or an array of thread IDs as
56 the input parameter and return per-thread information.
58 Thread CPU time A Java virtual machine implementation may support measuring the
59 CPU time for the current thread, for any thread, or for no threads.
61 The (|java.lang.management.ThreadMXBean|) method can be used to determine if a
62 Java virtual machine supports measuring of the CPU time for any thread. The
63 (|java.lang.management.ThreadMXBean|) method can be used to determine if a Java
64 virtual machine supports measuring of the CPU time for the current thread. A
65 Java virtual machine implementation that supports CPU time measurement for any
66 thread will also support that for the current thread.
68 The CPU time provided by this interface has nanosecond precision but not
69 necessarily nanosecond accuracy.
71 A Java virtual machine may disable CPU time measurement by default. The
72 (|java.lang.management.ThreadMXBean|) and (|java.lang.management.ThreadMXBean|)
73 methods can be used to test if CPU time measurement is enabled and to
74 enable/disable this support respectively. Enabling thread CPU measurement could
75 be expensive in some Java virtual machine implementations.
77 Thread Contention Monitoring Some Java virtual machines may support thread
78 contention monitoring. The (|java.lang.management.ThreadMXBean|) method can be
79 used to determine if a Java virtual machine supports thread contention
82 The thread contention monitoring is disabled by default. The
83 (|java.lang.management.ThreadMXBean|) method can be used to enable thread
84 contention monitoring.
87 *java.lang.management.ThreadMXBean.findMonitorDeadlockedThreads()*
89 public long findMonitorDeadlockedThreads()
91 Finds cycles of threads that are in deadlock waiting to acquire object
92 monitors. That is, threads that are blocked waiting to enter a synchronization
93 block or waiting to reenter a synchronization block after an
94 Object.wait(|java.lang.Object|) call, where each thread owns one monitor while
95 trying to obtain another monitor already held by another thread in a cycle.
97 More formally, a thread is monitor deadlocked if it is part of a cycle in the
98 relation "is waiting for an object monitor owned by". In the simplest case,
99 thread A is blocked waiting for a monitor owned by thread B, and thread B is
100 blocked waiting for a monitor owned by thread A.
102 This method is designed for troubleshooting use, but not for synchronization
103 control. It might be an expensive operation.
106 Returns: an array of IDs of the threads that are monitor deadlocked, if any; null
108 *java.lang.management.ThreadMXBean.getAllThreadIds()*
110 public long getAllThreadIds()
112 Returns all live thread IDs. Some threads included in the returned array may
113 have been terminated when this method returns.
116 Returns: an array of long, each is a thread ID.
117 *java.lang.management.ThreadMXBean.getCurrentThreadCpuTime()*
119 public long getCurrentThreadCpuTime()
121 Returns the total CPU time for the current thread in nanoseconds. The returned
122 value is of nanoseconds precison but not necessarily nanoseconds accuracy. If
123 the implementation distinguishes between user mode time and system mode time,
124 the returned CPU time is the amount of time that the current thread has
125 executed in user mode or system mode.
127 This is a convenient method for local management use and is equivalent to
130 getThreadCpuTime(|java.lang.management.ThreadMXBean|)
131 (Thread.currentThread().getId());
134 Returns: the total CPU time for the current thread if CPU time measurement is enabled;
136 *java.lang.management.ThreadMXBean.getCurrentThreadUserTime()*
138 public long getCurrentThreadUserTime()
140 Returns the CPU time that the current thread has executed in user mode in
141 nanoseconds. The returned value is of nanoseconds precison but not necessarily
142 nanoseconds accuracy.
144 This is a convenient method for local management use and is equivalent to
147 getThreadUserTime(|java.lang.management.ThreadMXBean|)
148 (Thread.currentThread().getId());
151 Returns: the user-level CPU time for the current thread if CPU time measurement is
152 enabled; -1 otherwise.
153 *java.lang.management.ThreadMXBean.getDaemonThreadCount()*
155 public int getDaemonThreadCount()
157 Returns the current number of live daemon threads.
160 Returns: the current number of live daemon threads.
161 *java.lang.management.ThreadMXBean.getPeakThreadCount()*
163 public int getPeakThreadCount()
165 Returns the peak live thread count since the Java virtual machine started or
169 Returns: the peak live thread count.
170 *java.lang.management.ThreadMXBean.getThreadCount()*
172 public int getThreadCount()
174 Returns the current number of live threads including both daemon and non-daemon
178 Returns: the current number of live threads.
179 *java.lang.management.ThreadMXBean.getThreadCpuTime(long)*
181 public long getThreadCpuTime(long id)
183 Returns the total CPU time for a thread of the specified ID in nanoseconds. The
184 returned value is of nanoseconds precision but not necessarily nanoseconds
185 accuracy. If the implementation distinguishes between user mode time and system
186 mode time, the returned CPU time is the amount of time that the thread has
187 executed in user mode or system mode.
189 If the thread of the specified ID is not alive or does not exist, this method
190 returns -1. If CPU time measurement is disabled, this method returns -1. A
191 thread is alive if it has been started and has not yet died.
193 If CPU time measurement is enabled after the thread has started, the Java
194 virtual machine implementation may choose any time up to and including the time
195 that the capability is enabled as the point where CPU time measurement starts.
197 id - the thread ID of a thread
199 Returns: the total CPU time for a thread of the specified ID if the thread of the
200 specified ID exists, the thread is alive, and CPU time measurement
201 is enabled; -1 otherwise.
202 *java.lang.management.ThreadMXBean.getThreadInfo(long)*
204 public |java.lang.management.ThreadInfo| getThreadInfo(long id)
206 Returns the thread info for a thread of the specified id with no stack trace.
207 This method is equivalent to calling: getThreadInfo(id,
208 0);(|java.lang.management.ThreadMXBean|)
210 This method returns a ThreadInfo object representing the thread information for
211 the thread of the specified ID. The stack trace in the returned ThreadInfo
212 object will be an empty array of StackTraceElement.
214 If a thread of the given ID is not alive or does not exist, this method will
215 return null. A thread is alive if it has been started and has not yet died.
217 MBeanServer access: The mapped type of ThreadInfo is CompositeData with
218 attributes as specified in ThreadInfo(|java.lang.management.ThreadInfo|) .
220 id - the thread ID of the thread. Must be positive.
222 Returns: a {@link ThreadInfo} object for the thread of the given ID with no stack trace;
223 null if the thread of the given ID is not alive or it does not
225 *java.lang.management.ThreadMXBean.getThreadInfo(long[])*
227 public |java.lang.management.ThreadInfo| getThreadInfo(long[] ids)
229 Returns the thread info for each thread whose ID is in the input array ids with
230 no stack trace. This method is equivalent to calling:
232 getThreadInfo(|java.lang.management.ThreadMXBean|) (ids, 0);
234 This method returns an array of the ThreadInfo objects. The stack trace in each
235 ThreadInfo object will be an empty array of StackTraceElement.
237 If a thread of a given ID is not alive or does not exist, the corresponding
238 element in the returned array will contain null. A thread is alive if it has
239 been started and has not yet died.
241 MBeanServer access: The mapped type of ThreadInfo is CompositeData with
242 attributes as specified in ThreadInfo(|java.lang.management.ThreadInfo|) .
244 ids - an array of thread IDs
246 Returns: an array of the {@link ThreadInfo} objects, each containing information about a
247 thread whose ID is in the corresponding element of the input array
249 *java.lang.management.ThreadMXBean.getThreadInfo(long[],int)*
251 public |java.lang.management.ThreadInfo| getThreadInfo(
255 Returns the thread info for each thread whose ID is in the input array ids. The
256 maxDepth parameter indicates the maximum number of StackTraceElement to be
257 retrieved from the stack trace. If maxDepth == Integer.MAX_VALUE, the entire
258 stack trace of the thread will be dumped. If maxDepth == 0, no stack trace of
259 the thread will be dumped.
261 When the Java virtual machine has no stack trace information about a thread or
262 maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array
263 of StackTraceElement.
265 This method returns an array of the ThreadInfo objects, each is the thread
266 information about the thread with the same index as in the ids array. If a
267 thread of the given ID is not alive or does not exist, null will be set in the
268 corresponding element in the returned array. A thread is alive if it has been
269 started and has not yet died.
271 MBeanServer access: The mapped type of ThreadInfo is CompositeData with
272 attributes as specified in ThreadInfo(|java.lang.management.ThreadInfo|) .
274 ids - an array of thread IDs
275 maxDepth - the maximum number of entries in the stack trace to be dumped.
276 Integer.MAX_VALUE could be used to request the entire stack to be
279 Returns: an array of the {@link ThreadInfo} objects, each containing information about a
280 thread whose ID is in the corresponding element of the input array
282 *java.lang.management.ThreadMXBean.getThreadInfo(long,int)*
284 public |java.lang.management.ThreadInfo| getThreadInfo(
288 Returns a thread info for a thread of the specified id. The maxDepth parameter
289 indicates the maximum number of StackTraceElement to be retrieved from the
290 stack trace. If maxDepth == Integer.MAX_VALUE, the entire stack trace of the
291 thread will be dumped. If maxDepth == 0, no stack trace of the thread will be
294 When the Java virtual machine has no stack trace information about a thread or
295 maxDepth == 0, the stack trace in the ThreadInfo object will be an empty array
296 of StackTraceElement.
298 If a thread of the given ID is not alive or does not exist, this method will
299 return null. A thread is alive if it has been started and has not yet died.
301 MBeanServer access: The mapped type of ThreadInfo is CompositeData with
302 attributes as specified in ThreadInfo(|java.lang.management.ThreadInfo|) .
304 id - the thread ID of the thread. Must be positive.
305 maxDepth - the maximum number of entries in the stack trace to be dumped.
306 Integer.MAX_VALUE could be used to request the entire stack to be
309 Returns: a {@link ThreadInfo} of the thread of the given ID. null if the thread of the
310 given ID is not alive or it does not exist.
311 *java.lang.management.ThreadMXBean.getThreadUserTime(long)*
313 public long getThreadUserTime(long id)
315 Returns the CPU time that a thread of the specified ID has executed in user
316 mode in nanoseconds. The returned value is of nanoseconds precision but not
317 necessarily nanoseconds accuracy.
319 If the thread of the specified ID is not alive or does not exist, this method
320 returns -1. If CPU time measurement is disabled, this method returns -1. A
321 thread is alive if it has been started and has not yet died.
323 If CPU time measurement is enabled after the thread has started, the Java
324 virtual machine implementation may choose any time up to and including the time
325 that the capability is enabled as the point where CPU time measurement starts.
327 id - the thread ID of a thread
329 Returns: the user-level CPU time for a thread of the specified ID if the thread of the
330 specified ID exists, the thread is alive, and CPU time measurement
331 is enabled; -1 otherwise.
332 *java.lang.management.ThreadMXBean.getTotalStartedThreadCount()*
334 public long getTotalStartedThreadCount()
336 Returns the total number of threads created and also started since the Java
337 virtual machine started.
340 Returns: the total number of threads started.
341 *java.lang.management.ThreadMXBean.isCurrentThreadCpuTimeSupported()*
343 public boolean isCurrentThreadCpuTimeSupported()
345 Tests if the Java virtual machine supports CPU time measurement for the current
346 thread. This method returns true if (|java.lang.management.ThreadMXBean|)
350 Returns: true if the Java virtual machine supports CPU time measurement for current
351 thread; false otherwise.
352 *java.lang.management.ThreadMXBean.isThreadContentionMonitoringEnabled()*
354 public boolean isThreadContentionMonitoringEnabled()
356 Tests if thread contention monitoring is enabled.
359 Returns: true if thread contention monitoring is enabled; false otherwise.
360 *java.lang.management.ThreadMXBean.isThreadContentionMonitoringSupported()*
362 public boolean isThreadContentionMonitoringSupported()
364 Tests if the Java virtual machine supports thread contention monitoring.
367 Returns: true if the Java virtual machine supports thread contention monitoring; false
369 *java.lang.management.ThreadMXBean.isThreadCpuTimeEnabled()*
371 public boolean isThreadCpuTimeEnabled()
373 Tests if thread CPU time measurement is enabled.
376 Returns: true if thread CPU time measurement is enabled; false otherwise.
377 *java.lang.management.ThreadMXBean.isThreadCpuTimeSupported()*
379 public boolean isThreadCpuTimeSupported()
381 Tests if the Java virtual machine implementation supports CPU time measurement
382 for any thread. A Java virtual machine implementation that supports CPU time
383 measurement for any thread will also support CPU time measurement for the
387 Returns: true if the Java virtual machine supports CPU time measurement for any thread;
389 *java.lang.management.ThreadMXBean.resetPeakThreadCount()*
391 public void resetPeakThreadCount()
393 Resets the peak thread count to the current number of live threads.
396 *java.lang.management.ThreadMXBean.setThreadContentionMonitoringEnabled(boolean)*
398 public void setThreadContentionMonitoringEnabled(boolean enable)
400 Enables or disables thread contention monitoring. Thread contention monitoring
401 is disabled by default.
403 enable - true to enable; false to disable.
405 *java.lang.management.ThreadMXBean.setThreadCpuTimeEnabled(boolean)*
407 public void setThreadCpuTimeEnabled(boolean enable)
409 Enables or disables thread CPU time measurement. The default is platform
412 enable - true to enable; false to disable.