src/java.management/share/classes/java/lang/management/ThreadMXBean.java
changeset 58223 778fc2dcbdaa
parent 58208 0f3c23c374a4
child 58348 c29e49148be7
equal deleted inserted replaced
58222:ee37c9b2eb61 58223:778fc2dcbdaa
   158      * Some threads included in the returned array
   158      * Some threads included in the returned array
   159      * may have been terminated when this method returns.
   159      * may have been terminated when this method returns.
   160      *
   160      *
   161      * @return an array of {@code long}, each is a thread ID.
   161      * @return an array of {@code long}, each is a thread ID.
   162      *
   162      *
   163      * @throws SecurityException if a security manager
   163      * @throws java.lang.SecurityException if a security manager
   164      *         exists and the caller does not have
   164      *         exists and the caller does not have
   165      *         ManagementPermission("monitor").
   165      *         ManagementPermission("monitor").
   166      */
   166      */
   167     public long[] getAllThreadIds();
   167     public long[] getAllThreadIds();
   168 
   168 
   197      * with no stack trace, no locked monitor and no synchronizer info;
   197      * with no stack trace, no locked monitor and no synchronizer info;
   198      * {@code null} if the thread of the given ID is not alive or
   198      * {@code null} if the thread of the given ID is not alive or
   199      * it does not exist.
   199      * it does not exist.
   200      *
   200      *
   201      * @throws IllegalArgumentException if {@code id <= 0}.
   201      * @throws IllegalArgumentException if {@code id <= 0}.
   202      * @throws SecurityException if a security manager
   202      * @throws java.lang.SecurityException if a security manager
   203      *         exists and the caller does not have
   203      *         exists and the caller does not have
   204      *         ManagementPermission("monitor").
   204      *         ManagementPermission("monitor").
   205      */
   205      */
   206     public ThreadInfo getThreadInfo(long id);
   206     public ThreadInfo getThreadInfo(long id);
   207 
   207 
   235      * element of the input array of IDs
   235      * element of the input array of IDs
   236      * with no stack trace, no locked monitor and no synchronizer info.
   236      * with no stack trace, no locked monitor and no synchronizer info.
   237      *
   237      *
   238      * @throws IllegalArgumentException if any element in the input array
   238      * @throws IllegalArgumentException if any element in the input array
   239      *         {@code ids} is {@code <= 0}.
   239      *         {@code ids} is {@code <= 0}.
   240      * @throws SecurityException if a security manager
   240      * @throws java.lang.SecurityException if a security manager
   241      *         exists and the caller does not have
   241      *         exists and the caller does not have
   242      *         ManagementPermission("monitor").
   242      *         ManagementPermission("monitor").
   243      */
   243      */
   244     public ThreadInfo[] getThreadInfo(long[] ids);
   244     public ThreadInfo[] getThreadInfo(long[] ids);
   245 
   245 
   282      * {@code null} if the thread of the given ID is not alive or
   282      * {@code null} if the thread of the given ID is not alive or
   283      * it does not exist.
   283      * it does not exist.
   284      *
   284      *
   285      * @throws IllegalArgumentException if {@code id <= 0}.
   285      * @throws IllegalArgumentException if {@code id <= 0}.
   286      * @throws IllegalArgumentException if {@code maxDepth is negative}.
   286      * @throws IllegalArgumentException if {@code maxDepth is negative}.
   287      * @throws SecurityException if a security manager
   287      * @throws java.lang.SecurityException if a security manager
   288      *         exists and the caller does not have
   288      *         exists and the caller does not have
   289      *         ManagementPermission("monitor").
   289      *         ManagementPermission("monitor").
   290      *
   290      *
   291      */
   291      */
   292     public ThreadInfo getThreadInfo(long id, int maxDepth);
   292     public ThreadInfo getThreadInfo(long id, int maxDepth);
   335      * synchronizer info.
   335      * synchronizer info.
   336      *
   336      *
   337      * @throws IllegalArgumentException if {@code maxDepth is negative}.
   337      * @throws IllegalArgumentException if {@code maxDepth is negative}.
   338      * @throws IllegalArgumentException if any element in the input array
   338      * @throws IllegalArgumentException if any element in the input array
   339      *      {@code ids} is {@code <= 0}.
   339      *      {@code ids} is {@code <= 0}.
   340      * @throws SecurityException if a security manager
   340      * @throws java.lang.SecurityException if a security manager
   341      *         exists and the caller does not have
   341      *         exists and the caller does not have
   342      *         ManagementPermission("monitor").
   342      *         ManagementPermission("monitor").
   343      *
   343      *
   344      */
   344      */
   345     public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);
   345     public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth);
   358      * Tests if thread contention monitoring is enabled.
   358      * Tests if thread contention monitoring is enabled.
   359      *
   359      *
   360      * @return {@code true} if thread contention monitoring is enabled;
   360      * @return {@code true} if thread contention monitoring is enabled;
   361      *         {@code false} otherwise.
   361      *         {@code false} otherwise.
   362      *
   362      *
   363      * @throws UnsupportedOperationException if the Java virtual
   363      * @throws java.lang.UnsupportedOperationException if the Java virtual
   364      * machine does not support thread contention monitoring.
   364      * machine does not support thread contention monitoring.
   365      *
   365      *
   366      * @see #isThreadContentionMonitoringSupported
   366      * @see #isThreadContentionMonitoringSupported
   367      */
   367      */
   368     public boolean isThreadContentionMonitoringEnabled();
   368     public boolean isThreadContentionMonitoringEnabled();
   372      * Thread contention monitoring is disabled by default.
   372      * Thread contention monitoring is disabled by default.
   373      *
   373      *
   374      * @param enable {@code true} to enable;
   374      * @param enable {@code true} to enable;
   375      *               {@code false} to disable.
   375      *               {@code false} to disable.
   376      *
   376      *
   377      * @throws UnsupportedOperationException if the Java
   377      * @throws java.lang.UnsupportedOperationException if the Java
   378      * virtual machine does not support thread contention monitoring.
   378      * virtual machine does not support thread contention monitoring.
   379      *
   379      *
   380      * @throws SecurityException if a security manager
   380      * @throws java.lang.SecurityException if a security manager
   381      *         exists and the caller does not have
   381      *         exists and the caller does not have
   382      *         ManagementPermission("control").
   382      *         ManagementPermission("control").
   383      *
   383      *
   384      * @see #isThreadContentionMonitoringSupported
   384      * @see #isThreadContentionMonitoringSupported
   385      */
   385      */
   392      * If the implementation distinguishes between user mode time and system
   392      * If the implementation distinguishes between user mode time and system
   393      * mode time, the returned CPU time is the amount of time that
   393      * mode time, the returned CPU time is the amount of time that
   394      * the current thread has executed in user mode or system mode.
   394      * the current thread has executed in user mode or system mode.
   395      *
   395      *
   396      * <p>
   396      * <p>
   397      * This is a convenience method for local management use and is
   397      * This is a convenient method for local management use and is
   398      * equivalent to calling:
   398      * equivalent to calling:
   399      * <blockquote><pre>
   399      * <blockquote><pre>
   400      *   {@link #getThreadCpuTime getThreadCpuTime}(Thread.currentThread().getId());
   400      *   {@link #getThreadCpuTime getThreadCpuTime}(Thread.currentThread().getId());
   401      * </pre></blockquote>
   401      * </pre></blockquote>
   402      *
   402      *
   403      * @return the total CPU time for the current thread if CPU time
   403      * @return the total CPU time for the current thread if CPU time
   404      * measurement is enabled; {@code -1} otherwise.
   404      * measurement is enabled; {@code -1} otherwise.
   405      *
   405      *
   406      * @throws UnsupportedOperationException if the Java
   406      * @throws java.lang.UnsupportedOperationException if the Java
   407      * virtual machine does not support CPU time measurement for
   407      * virtual machine does not support CPU time measurement for
   408      * the current thread.
   408      * the current thread.
   409      *
   409      *
   410      * @see #getCurrentThreadUserTime
   410      * @see #getCurrentThreadUserTime
   411      * @see #isCurrentThreadCpuTimeSupported
   411      * @see #isCurrentThreadCpuTimeSupported
   419      * in user mode in nanoseconds.
   419      * in user mode in nanoseconds.
   420      * The returned value is of nanoseconds precision but
   420      * The returned value is of nanoseconds precision but
   421      * not necessarily nanoseconds accuracy.
   421      * not necessarily nanoseconds accuracy.
   422      *
   422      *
   423      * <p>
   423      * <p>
   424      * This is a convenience method for local management use and is
   424      * This is a convenient method for local management use and is
   425      * equivalent to calling:
   425      * equivalent to calling:
   426      * <blockquote><pre>
   426      * <blockquote><pre>
   427      *   {@link #getThreadUserTime getThreadUserTime}(Thread.currentThread().getId());
   427      *   {@link #getThreadUserTime getThreadUserTime}(Thread.currentThread().getId());
   428      * </pre></blockquote>
   428      * </pre></blockquote>
   429      *
   429      *
   430      * @return the user-level CPU time for the current thread if CPU time
   430      * @return the user-level CPU time for the current thread if CPU time
   431      * measurement is enabled; {@code -1} otherwise.
   431      * measurement is enabled; {@code -1} otherwise.
   432      *
   432      *
   433      * @throws UnsupportedOperationException if the Java
   433      * @throws java.lang.UnsupportedOperationException if the Java
   434      * virtual machine does not support CPU time measurement for
   434      * virtual machine does not support CPU time measurement for
   435      * the current thread.
   435      * the current thread.
   436      *
   436      *
   437      * @see #getCurrentThreadCpuTime
   437      * @see #getCurrentThreadCpuTime
   438      * @see #isCurrentThreadCpuTimeSupported
   438      * @see #isCurrentThreadCpuTimeSupported
   465      * if the thread of the specified ID exists, the thread is alive,
   465      * if the thread of the specified ID exists, the thread is alive,
   466      * and CPU time measurement is enabled;
   466      * and CPU time measurement is enabled;
   467      * {@code -1} otherwise.
   467      * {@code -1} otherwise.
   468      *
   468      *
   469      * @throws IllegalArgumentException if {@code id <= 0}.
   469      * @throws IllegalArgumentException if {@code id <= 0}.
   470      * @throws UnsupportedOperationException if the Java
   470      * @throws java.lang.UnsupportedOperationException if the Java
   471      * virtual machine does not support CPU time measurement for
   471      * virtual machine does not support CPU time measurement for
   472      * other threads.
   472      * other threads.
   473      *
   473      *
   474      * @see #getThreadUserTime
   474      * @see #getThreadUserTime
   475      * @see #isThreadCpuTimeSupported
   475      * @see #isThreadCpuTimeSupported
   500      * if the thread of the specified ID exists, the thread is alive,
   500      * if the thread of the specified ID exists, the thread is alive,
   501      * and CPU time measurement is enabled;
   501      * and CPU time measurement is enabled;
   502      * {@code -1} otherwise.
   502      * {@code -1} otherwise.
   503      *
   503      *
   504      * @throws IllegalArgumentException if {@code id <= 0}.
   504      * @throws IllegalArgumentException if {@code id <= 0}.
   505      * @throws UnsupportedOperationException if the Java
   505      * @throws java.lang.UnsupportedOperationException if the Java
   506      * virtual machine does not support CPU time measurement for
   506      * virtual machine does not support CPU time measurement for
   507      * other threads.
   507      * other threads.
   508      *
   508      *
   509      * @see #getThreadCpuTime
   509      * @see #getThreadCpuTime
   510      * @see #isThreadCpuTimeSupported
   510      * @see #isThreadCpuTimeSupported
   546      * Tests if thread CPU time measurement is enabled.
   546      * Tests if thread CPU time measurement is enabled.
   547      *
   547      *
   548      * @return {@code true} if thread CPU time measurement is enabled;
   548      * @return {@code true} if thread CPU time measurement is enabled;
   549      *         {@code false} otherwise.
   549      *         {@code false} otherwise.
   550      *
   550      *
   551      * @throws UnsupportedOperationException if the Java virtual
   551      * @throws java.lang.UnsupportedOperationException if the Java virtual
   552      * machine does not support CPU time measurement for other threads
   552      * machine does not support CPU time measurement for other threads
   553      * nor for the current thread.
   553      * nor for the current thread.
   554      *
   554      *
   555      * @see #isThreadCpuTimeSupported
   555      * @see #isThreadCpuTimeSupported
   556      * @see #isCurrentThreadCpuTimeSupported
   556      * @see #isCurrentThreadCpuTimeSupported
   562      * is platform dependent.
   562      * is platform dependent.
   563      *
   563      *
   564      * @param enable {@code true} to enable;
   564      * @param enable {@code true} to enable;
   565      *               {@code false} to disable.
   565      *               {@code false} to disable.
   566      *
   566      *
   567      * @throws UnsupportedOperationException if the Java
   567      * @throws java.lang.UnsupportedOperationException if the Java
   568      * virtual machine does not support CPU time measurement for
   568      * virtual machine does not support CPU time measurement for
   569      * any threads nor for the current thread.
   569      * any threads nor for the current thread.
   570      *
   570      *
   571      * @throws SecurityException if a security manager
   571      * @throws java.lang.SecurityException if a security manager
   572      *         exists and the caller does not have
   572      *         exists and the caller does not have
   573      *         ManagementPermission("control").
   573      *         ManagementPermission("control").
   574      *
   574      *
   575      * @see #isThreadCpuTimeSupported
   575      * @see #isThreadCpuTimeSupported
   576      * @see #isCurrentThreadCpuTimeSupported
   576      * @see #isCurrentThreadCpuTimeSupported
   602      * should be used.
   602      * should be used.
   603      *
   603      *
   604      * @return an array of IDs of the threads that are monitor
   604      * @return an array of IDs of the threads that are monitor
   605      * deadlocked, if any; {@code null} otherwise.
   605      * deadlocked, if any; {@code null} otherwise.
   606      *
   606      *
   607      * @throws SecurityException if a security manager
   607      * @throws java.lang.SecurityException if a security manager
   608      *         exists and the caller does not have
   608      *         exists and the caller does not have
   609      *         ManagementPermission("monitor").
   609      *         ManagementPermission("monitor").
   610      *
   610      *
   611      * @see #findDeadlockedThreads
   611      * @see #findDeadlockedThreads
   612      */
   612      */
   614 
   614 
   615     /**
   615     /**
   616      * Resets the peak thread count to the current number of
   616      * Resets the peak thread count to the current number of
   617      * live threads.
   617      * live threads.
   618      *
   618      *
   619      * @throws SecurityException if a security manager
   619      * @throws java.lang.SecurityException if a security manager
   620      *         exists and the caller does not have
   620      *         exists and the caller does not have
   621      *         ManagementPermission("control").
   621      *         ManagementPermission("control").
   622      *
   622      *
   623      * @see #getPeakThreadCount
   623      * @see #getPeakThreadCount
   624      * @see #getThreadCount
   624      * @see #getThreadCount
   640      *
   640      *
   641      * @return an array of IDs of the threads that are
   641      * @return an array of IDs of the threads that are
   642      * deadlocked waiting for object monitors or ownable synchronizers, if any;
   642      * deadlocked waiting for object monitors or ownable synchronizers, if any;
   643      * {@code null} otherwise.
   643      * {@code null} otherwise.
   644      *
   644      *
   645      * @throws SecurityException if a security manager
   645      * @throws java.lang.SecurityException if a security manager
   646      *         exists and the caller does not have
   646      *         exists and the caller does not have
   647      *         ManagementPermission("monitor").
   647      *         ManagementPermission("monitor").
   648      * @throws UnsupportedOperationException if the Java virtual
   648      * @throws java.lang.UnsupportedOperationException if the Java virtual
   649      * machine does not support monitoring of ownable synchronizer usage.
   649      * machine does not support monitoring of ownable synchronizer usage.
   650      *
   650      *
   651      * @see #isSynchronizerUsageSupported
   651      * @see #isSynchronizerUsageSupported
   652      * @see #findMonitorDeadlockedThreads
   652      * @see #findMonitorDeadlockedThreads
   653      * @since 1.6
   653      * @since 1.6
   702      *
   702      *
   703      * @return an array of the {@link ThreadInfo} objects, each containing
   703      * @return an array of the {@link ThreadInfo} objects, each containing
   704      * information about a thread whose ID is in the corresponding
   704      * information about a thread whose ID is in the corresponding
   705      * element of the input array of IDs.
   705      * element of the input array of IDs.
   706      *
   706      *
   707      * @throws SecurityException if a security manager
   707      * @throws java.lang.SecurityException if a security manager
   708      *         exists and the caller does not have
   708      *         exists and the caller does not have
   709      *         ManagementPermission("monitor").
   709      *         ManagementPermission("monitor").
   710      * @throws UnsupportedOperationException
   710      * @throws java.lang.UnsupportedOperationException
   711      *         <ul>
   711      *         <ul>
   712      *           <li>if {@code lockedMonitors} is {@code true} but
   712      *           <li>if {@code lockedMonitors} is {@code true} but
   713      *               the Java virtual machine does not support monitoring
   713      *               the Java virtual machine does not support monitoring
   714      *               of {@linkplain #isObjectMonitorUsageSupported
   714      *               of {@linkplain #isObjectMonitorUsageSupported
   715      *               object monitor usage}; or</li>
   715      *               object monitor usage}; or</li>
   792      * @return an array of the {@link ThreadInfo} objects, each containing
   792      * @return an array of the {@link ThreadInfo} objects, each containing
   793      * information about a thread whose ID is in the corresponding
   793      * information about a thread whose ID is in the corresponding
   794      * element of the input array of IDs.
   794      * element of the input array of IDs.
   795      *
   795      *
   796      * @throws IllegalArgumentException if {@code maxDepth} is negative.
   796      * @throws IllegalArgumentException if {@code maxDepth} is negative.
   797      * @throws SecurityException if a security manager
   797      * @throws java.lang.SecurityException if a security manager
   798      *         exists and the caller does not have
   798      *         exists and the caller does not have
   799      *         ManagementPermission("monitor").
   799      *         ManagementPermission("monitor").
   800      * @throws UnsupportedOperationException
   800      * @throws java.lang.UnsupportedOperationException
   801      *         <ul>
   801      *         <ul>
   802      *           <li>if {@code lockedMonitors} is {@code true} but
   802      *           <li>if {@code lockedMonitors} is {@code true} but
   803      *               the Java virtual machine does not support monitoring
   803      *               the Java virtual machine does not support monitoring
   804      *               of {@linkplain #isObjectMonitorUsageSupported
   804      *               of {@linkplain #isObjectMonitorUsageSupported
   805      *               object monitor usage}; or</li>
   805      *               object monitor usage}; or</li>
   833      * @param  lockedSynchronizers if {@code true}, dump all locked
   833      * @param  lockedSynchronizers if {@code true}, dump all locked
   834      *             ownable synchronizers.
   834      *             ownable synchronizers.
   835      *
   835      *
   836      * @return an array of {@link ThreadInfo} for all live threads.
   836      * @return an array of {@link ThreadInfo} for all live threads.
   837      *
   837      *
   838      * @throws SecurityException if a security manager
   838      * @throws java.lang.SecurityException if a security manager
   839      *         exists and the caller does not have
   839      *         exists and the caller does not have
   840      *         ManagementPermission("monitor").
   840      *         ManagementPermission("monitor").
   841      * @throws UnsupportedOperationException
   841      * @throws java.lang.UnsupportedOperationException
   842      *         <ul>
   842      *         <ul>
   843      *           <li>if {@code lockedMonitors} is {@code true} but
   843      *           <li>if {@code lockedMonitors} is {@code true} but
   844      *               the Java virtual machine does not support monitoring
   844      *               the Java virtual machine does not support monitoring
   845      *               of {@linkplain #isObjectMonitorUsageSupported
   845      *               of {@linkplain #isObjectMonitorUsageSupported
   846      *               object monitor usage}; or</li>
   846      *               object monitor usage}; or</li>
   882      * {@link StackTraceElement} to be retrieved from the stack trace.
   882      * {@link StackTraceElement} to be retrieved from the stack trace.
   883      *
   883      *
   884      * @return an array of {@link ThreadInfo} for all live threads.
   884      * @return an array of {@link ThreadInfo} for all live threads.
   885      *
   885      *
   886      * @throws IllegalArgumentException if {@code maxDepth} is negative.
   886      * @throws IllegalArgumentException if {@code maxDepth} is negative.
   887      * @throws SecurityException if a security manager
   887      * @throws java.lang.SecurityException if a security manager
   888      *         exists and the caller does not have
   888      *         exists and the caller does not have
   889      *         ManagementPermission("monitor").
   889      *         ManagementPermission("monitor").
   890      * @throws UnsupportedOperationException
   890      * @throws java.lang.UnsupportedOperationException
   891      *         <ul>
   891      *         <ul>
   892      *           <li>if {@code lockedMonitors} is {@code true} but
   892      *           <li>if {@code lockedMonitors} is {@code true} but
   893      *               the Java virtual machine does not support monitoring
   893      *               the Java virtual machine does not support monitoring
   894      *               of {@linkplain #isObjectMonitorUsageSupported
   894      *               of {@linkplain #isObjectMonitorUsageSupported
   895      *               object monitor usage}; or</li>
   895      *               object monitor usage}; or</li>