Name

ThreadMXBean

Synopsis

This MXBean interface allows monitoring of thread usage in a Java VM. A number of methods, such as getThreadCount( ) and getPeakThreadCount( ), return information about all running threads. Other methods return information about individual threads. Threads are identified by their thread id, which is a long integer. getAllThreadIds( ) returns all ids as an array of long. Complete information, including stack trace, about a thread or set of threads can be obtained with the getThreadInfo( ) methods, which return ThreadInfo objects.

If isThreadCpuTimeSupported( ) returns true, you can enable thread timing with setThreadCpuTimeEnabled( ) and query the runtime of a specific thread with getThreadCpuTime( ) and getThreadUserTime( ). The values returned by these methods are measured in nanoseconds.

One of the potentially most useful methods of this interface is findMonitorDeadlockedThreads( ) . It looks for cycles of threads that are deadlocked waiting to lock objects whose locks are held by other threads in the cycle.

public interface ThreadMXBean {
// Public Instance Methods
     long[ ] findMonitorDeadlockedThreads( );  
     long[ ] getAllThreadIds( );  
     long getCurrentThreadCpuTime( );  
     long getCurrentThreadUserTime( );  
     int getDaemonThreadCount( );  
     int getPeakThreadCount( );  
     int getThreadCount( );  
     long getThreadCpuTime(long id);  
     ThreadInfo getThreadInfo(long id);  
     ThreadInfo[ ] getThreadInfo(long[ ] ids);  
     ThreadInfo[ ] getThreadInfo(long[ ] ids, int maxDepth); ThreadInfo ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.