jdk/src/share/classes/java/lang/management/ThreadInfo.java
author alanb
Mon, 01 Oct 2012 15:36:57 +0100
changeset 14014 da3648e13e67
parent 13803 889df16bef60
child 14342 8435a30053c1
permissions -rw-r--r--
8000269: Cleanup javadoc warnings Reviewed-by: lancea, darcy, ulfzibis, iris, naoto, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.management.openmbean.CompositeData;
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
    29
import sun.management.ManagementFactoryHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.management.ThreadInfoCompositeData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import static java.lang.Thread.State.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Thread information. <tt>ThreadInfo</tt> contains the information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * about a thread including:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <h4>General thread information</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   <li>Thread ID.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   <li>Name of the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <h4>Execution information</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *   <li>Thread state.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *   <li>The object upon which the thread is blocked due to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *       <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *       <li>waiting to enter a synchronization block/method, or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *       <li>waiting to be notified in a {@link Object#wait Object.wait} method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *           or</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *       <li>parking due to a {@link java.util.concurrent.locks.LockSupport#park
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *           LockSupport.park} call.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *       </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *   </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *   <li>The ID of the thread that owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *       that the thread is blocked.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *   <li>Stack trace of the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *   <li>List of object monitors locked by the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *   <li>List of <a href="LockInfo.html#OwnableSynchronizer">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *       ownable synchronizers</a> locked by the thread.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <h4><a name="SyncStats">Synchronization Statistics</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *   <li>The number of times that the thread has blocked for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *       synchronization or waited for notification.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *   <li>The accumulated elapsed time that the thread has blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *       for synchronization or waited for notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *       since {@link ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *       thread contention monitoring}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *       was enabled. Some Java virtual machine implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *       may not support this.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *       {@link ThreadMXBean#isThreadContentionMonitoringSupported()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *       method can be used to determine if a Java virtual machine
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *       supports this.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>This thread information class is designed for use in monitoring of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * the system, not for synchronization control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <h4>MXBean Mapping</h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <tt>ThreadInfo</tt> is mapped to a {@link CompositeData CompositeData}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * with attributes as specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * the {@link #from from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @see ThreadMXBean#getThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * @see ThreadMXBean#dumpAllThreads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class ThreadInfo {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private String       threadName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private long         threadId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private long         blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private long         blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private long         waitedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private long         waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private LockInfo     lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private String       lockName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private long         lockOwnerId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String       lockOwnerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private boolean      inNative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private boolean      suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private Thread.State threadState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private StackTraceElement[] stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private MonitorInfo[]       lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private LockInfo[]          lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private static MonitorInfo[] EMPTY_MONITORS = new MonitorInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static LockInfo[] EMPTY_SYNCS = new LockInfo[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Constructor of ThreadInfo created by the JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param stackTrace    Thread stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                       long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                       long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                       StackTraceElement[] stackTrace) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        initialize(t, state, lockObj, lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                   blockedCount, blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                   waitedCount, waitedTime, stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                   EMPTY_MONITORS, EMPTY_SYNCS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Constructor of ThreadInfo created by the JVM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * for {@link ThreadMXBean#getThreadInfo(long[],boolean,boolean)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * and {@link ThreadMXBean#dumpAllThreads}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param stackTrace    Thread stack trace
14014
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   150
     * @param monitors      List of locked monitors
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   151
     * @param stackDepths   List of stack depths
da3648e13e67 8000269: Cleanup javadoc warnings
alanb
parents: 13803
diff changeset
   152
     * @param synchronizers List of locked synchronizers
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private ThreadInfo(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                       long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                       long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                       StackTraceElement[] stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                       Object[] monitors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                       int[] stackDepths,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                       Object[] synchronizers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int numMonitors = (monitors == null ? 0 : monitors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        MonitorInfo[] lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (numMonitors == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            lockedMonitors = EMPTY_MONITORS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            lockedMonitors = new MonitorInfo[numMonitors];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            for (int i = 0; i < numMonitors; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                Object lock = monitors[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                String className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                int identityHashCode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                int depth = stackDepths[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                StackTraceElement ste = (depth >= 0 ? stackTrace[depth]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                                    : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                lockedMonitors[i] = new MonitorInfo(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                    identityHashCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                                    depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                                    ste);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        int numSyncs = (synchronizers == null ? 0 : synchronizers.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        LockInfo[] lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if (numSyncs == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            lockedSynchronizers = EMPTY_SYNCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            lockedSynchronizers = new LockInfo[numSyncs];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            for (int i = 0; i < numSyncs; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                Object lock = synchronizers[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                String className = lock.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                int identityHashCode = System.identityHashCode(lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                lockedSynchronizers[i] = new LockInfo(className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                                      identityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        initialize(t, state, lockObj, lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                   blockedCount, blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                   waitedCount, waitedTime, stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                   lockedMonitors, lockedSynchronizers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Initialize ThreadInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param t             Thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param state         Thread state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @param lockObj       Object on which the thread is blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param lockOwner     the thread holding the lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * @param blockedCount  Number of times blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param blockedTime   Approx time blocked to enter a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @param waitedCount   Number of times waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param waitedTime    Approx time waited on a lock
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param stackTrace    Thread stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param lockedMonitors List of locked monitors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param lockedSynchronizers List of locked synchronizers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    private void initialize(Thread t, int state, Object lockObj, Thread lockOwner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                            long blockedCount, long blockedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                            long waitedCount, long waitedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                            StackTraceElement[] stackTrace,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                            MonitorInfo[] lockedMonitors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            LockInfo[] lockedSynchronizers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        this.threadId = t.getId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this.threadName = t.getName();
401
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   225
        this.threadState = ManagementFactoryHelper.toThreadState(state);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   226
        this.suspended = ManagementFactoryHelper.isThreadSuspended(state);
ef01e0dccd63 6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents: 2
diff changeset
   227
        this.inNative = ManagementFactoryHelper.isThreadRunningNative(state);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        this.blockedCount = blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        this.blockedTime = blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        this.waitedCount = waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        this.waitedTime = waitedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        if (lockObj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            this.lock = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            this.lockName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            this.lock = new LockInfo(lockObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            this.lockName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                lock.getClassName() + '@' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                    Integer.toHexString(lock.getIdentityHashCode());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (lockOwner == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            this.lockOwnerId = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            this.lockOwnerName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            this.lockOwnerId = lockOwner.getId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            this.lockOwnerName = lockOwner.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        if (stackTrace == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            this.stackTrace = NO_STACK_TRACE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            this.stackTrace = stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        this.lockedMonitors = lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        this.lockedSynchronizers = lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Constructs a <tt>ThreadInfo</tt> object from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * {@link CompositeData CompositeData}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private ThreadInfo(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        ThreadInfoCompositeData ticd = ThreadInfoCompositeData.getInstance(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        threadId = ticd.threadId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        threadName = ticd.threadName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        blockedTime = ticd.blockedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        blockedCount = ticd.blockedCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        waitedTime = ticd.waitedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        waitedCount = ticd.waitedCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        lockName = ticd.lockName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        lockOwnerId = ticd.lockOwnerId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        lockOwnerName = ticd.lockOwnerName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        threadState = ticd.threadState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        suspended = ticd.suspended();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        inNative = ticd.inNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        stackTrace = ticd.stackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // 6.0 attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (ticd.isCurrentVersion()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            lock = ticd.lockInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            lockedMonitors = ticd.lockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            lockedSynchronizers = ticd.lockedSynchronizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            // lockInfo is a new attribute added in 1.6 ThreadInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            // If cd is a 5.0 version, construct the LockInfo object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            //  from the lockName value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (lockName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                String result[] = lockName.split("@");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                if (result.length == 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                    int identityHashCode = Integer.parseInt(result[1], 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                    lock = new LockInfo(result[0], identityHashCode);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                    assert result.length == 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    lock = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                lock = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            lockedMonitors = EMPTY_MONITORS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            lockedSynchronizers = EMPTY_SYNCS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Returns the ID of the thread associated with this <tt>ThreadInfo</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return the ID of the associated thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public long getThreadId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return threadId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Returns the name of the thread associated with this <tt>ThreadInfo</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @return the name of the associated thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public String getThreadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return threadName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Returns the state of the thread associated with this <tt>ThreadInfo</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * @return <tt>Thread.State</tt> of the associated thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public Thread.State getThreadState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         return threadState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Returns the approximate accumulated elapsed time (in milliseconds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * that the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * has blocked to enter or reenter a monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * since thread contention monitoring is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * I.e. the total accumulated time the thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * {@link java.lang.Thread.State#BLOCKED BLOCKED} state since thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * contention monitoring was last enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * This method returns <tt>-1</tt> if thread contention monitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <p>The Java virtual machine may measure the time with a high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * resolution timer.  This statistic is reset when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * the thread contention monitoring is reenabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return the approximate accumulated elapsed time in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * that a thread entered the <tt>BLOCKED</tt> state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <tt>-1</tt> if thread contention monitoring is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @throws java.lang.UnsupportedOperationException if the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * virtual machine does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see ThreadMXBean#isThreadContentionMonitoringSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @see ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    public long getBlockedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        return blockedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * Returns the total number of times that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * blocked to enter or reenter a monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * I.e. the number of times a thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * {@link java.lang.Thread.State#BLOCKED BLOCKED} state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @return the total number of times that the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * entered the <tt>BLOCKED</tt> state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public long getBlockedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        return blockedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Returns the approximate accumulated elapsed time (in milliseconds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * that the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * has waited for notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * since thread contention monitoring is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * I.e. the total accumulated time the thread has been in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * since thread contention monitoring is enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * This method returns <tt>-1</tt> if thread contention monitoring
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * <p>The Java virtual machine may measure the time with a high
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * resolution timer.  This statistic is reset when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * the thread contention monitoring is reenabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return the approximate accumulated elapsed time in milliseconds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * that a thread has been in the <tt>WAITING</tt> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * <tt>TIMED_WAITING</tt> state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * <tt>-1</tt> if thread contention monitoring is disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @throws java.lang.UnsupportedOperationException if the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * virtual machine does not support this operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @see ThreadMXBean#isThreadContentionMonitoringSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see ThreadMXBean#setThreadContentionMonitoringEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public long getWaitedTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        return waitedTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Returns the total number of times that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * waited for notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * I.e. the number of times that a thread has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return the total number of times that the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * was in the <tt>WAITING</tt> or <tt>TIMED_WAITING</tt> state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public long getWaitedCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        return waitedCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Returns the <tt>LockInfo</tt> of an object for which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * is blocked waiting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * A thread can be blocked waiting for one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <li>an object monitor to be acquired for entering or reentering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *     a synchronization block/method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *     <br>The thread is in the {@link java.lang.Thread.State#BLOCKED BLOCKED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *     state waiting to enter the <tt>synchronized</tt> statement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *     or method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *     <p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <li>an object monitor to be notified by another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *     <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *     or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *     due to a call to the {@link Object#wait Object.wait} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *     <p></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * <li>a synchronization object responsible for the thread parking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *     <br>The thread is in the {@link java.lang.Thread.State#WAITING WAITING}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *     or {@link java.lang.Thread.State#TIMED_WAITING TIMED_WAITING} state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *     due to a call to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *     {@link java.util.concurrent.locks.LockSupport#park(Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *     LockSupport.park} method.  The synchronization object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *     is the object returned from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *     {@link java.util.concurrent.locks.LockSupport#getBlocker
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *     LockSupport.getBlocker} method. Typically it is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *     <a href="LockInfo.html#OwnableSynchronizer"> ownable synchronizer</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *     or a {@link java.util.concurrent.locks.Condition Condition}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <p>This method returns <tt>null</tt> if the thread is not in any of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * the above conditions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return <tt>LockInfo</tt> of an object for which the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *         is blocked waiting if any; <tt>null</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public LockInfo getLockInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return lock;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * Returns the {@link LockInfo#toString string representation}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * of an object for which the thread associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * <tt>ThreadInfo</tt> is blocked waiting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * This method is equivalent to calling:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * getLockInfo().toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * <p>This method will return <tt>null</tt> if this thread is not blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return the string representation of the object on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * the thread is blocked if any;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <tt>null</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public String getLockName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        return lockName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * Returns the ID of the thread which owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * for which the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * is blocked waiting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * This method will return <tt>-1</tt> if this thread is not blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @return the thread ID of the owner thread of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * this thread is blocked on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * <tt>-1</tt> if this thread is not blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * or if the object lis not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    public long getLockOwnerId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return lockOwnerId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Returns the name of the thread which owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * for which the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * is blocked waiting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * This method will return <tt>null</tt> if this thread is not blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * waiting for any object or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @return the name of the thread that owns the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * this thread is blocked on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <tt>null</tt> if this thread is not blocked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * or if the object is not owned by any thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @see #getLockInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public String getLockOwnerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        return lockOwnerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * Returns the stack trace of the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * associated with this <tt>ThreadInfo</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * If no stack trace was requested for this thread info, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * If the returned array is of non-zero length then the first element of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * the array represents the top of the stack, which is the most recent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * method invocation in the sequence.  The last element of the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * represents the bottom of the stack, which is the least recent method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * invocation in the sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <p>Some Java virtual machines may, under some circumstances, omit one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * or more stack frames from the stack trace.  In the extreme case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * a virtual machine that has no stack trace information concerning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * is permitted to return a zero-length array from this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @return an array of <tt>StackTraceElement</tt> objects of the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public StackTraceElement[] getStackTrace() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        return stackTrace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Tests if the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * is suspended.  This method returns <tt>true</tt> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * {@link Thread#suspend} has been called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @return <tt>true</tt> if the thread is suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *         <tt>false</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    public boolean isSuspended() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         return suspended;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * Tests if the thread associated with this <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * is executing native code via the Java Native Interface (JNI).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * The JNI native code does not include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * the virtual machine support code or the compiled native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * code generated by the virtual machine.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @return <tt>true</tt> if the thread is executing native code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *         <tt>false</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    public boolean isInNative() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         return inNative;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * Returns a string representation of this thread info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * The format of this string depends on the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * The returned string will typically include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * the {@linkplain #getThreadName thread name},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * the {@linkplain #getThreadId thread ID},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * its {@linkplain #getThreadState state},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * and a {@linkplain #getStackTrace stack trace} if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * @return a string representation of this thread info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        StringBuilder sb = new StringBuilder("\"" + getThreadName() + "\"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                             " Id=" + getThreadId() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                             getThreadState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if (getLockName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            sb.append(" on " + getLockName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        if (getLockOwnerName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            sb.append(" owned by \"" + getLockOwnerName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                      "\" Id=" + getLockOwnerId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        if (isSuspended()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            sb.append(" (suspended)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        if (isInNative()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            sb.append(" (in native)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        for (; i < stackTrace.length && i < MAX_FRAMES; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            StackTraceElement ste = stackTrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            sb.append("\tat " + ste.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            if (i == 0 && getLockInfo() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                Thread.State ts = getThreadState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                switch (ts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    case BLOCKED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                        sb.append("\t-  blocked on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    case WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        sb.append("\t-  waiting on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    case TIMED_WAITING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                        sb.append("\t-  waiting on " + getLockInfo());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            for (MonitorInfo mi : lockedMonitors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                if (mi.getLockedStackDepth() == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    sb.append("\t-  locked " + mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
       if (i < stackTrace.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
           sb.append("\t...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
           sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
       LockInfo[] locks = getLockedSynchronizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
       if (locks.length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
           sb.append("\n\tNumber of locked synchronizers = " + locks.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
           sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
           for (LockInfo li : locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
               sb.append("\t- " + li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
               sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
       sb.append('\n');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
       return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    private static final int MAX_FRAMES = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * Returns a <tt>ThreadInfo</tt> object represented by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * given <tt>CompositeData</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * The given <tt>CompositeData</tt> must contain the following attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * unless otherwise specified below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * <table border>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *   <th align=left>Attribute Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *   <th align=left>Type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *   <td>threadId</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *   <td>threadName</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *   <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *   <td>threadState</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *   <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *   <td>suspended</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *   <td><tt>java.lang.Boolean</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *   <td>inNative</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *   <td><tt>java.lang.Boolean</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *   <td>blockedCount</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *   <td>blockedTime</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     *   <td>waitedCount</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     *   <td>waitedTime</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     *   <td>lockInfo</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     *   <td><tt>javax.management.openmbean.CompositeData</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     *       - the mapped type for {@link LockInfo} as specified in the
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   700
     *         {@link LockInfo#from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *       <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     *       If <tt>cd</tt> does not contain this attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *       the <tt>LockInfo</tt> object will be constructed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *       the value of the <tt>lockName</tt> attribute. </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *   <td>lockName</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *   <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *   <td>lockOwnerId</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *   <td><tt>java.lang.Long</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *   <td>lockOwnerName</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     *   <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *   <td><a name="StackTrace">stackTrace</a></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     *   <td><tt>javax.management.openmbean.CompositeData[]</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     *       <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *       Each element is a <tt>CompositeData</tt> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *       StackTraceElement containing the following attributes:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     *       <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     *       <table cellspacing=1 cellpadding=0>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     *         <th align=left>Attribute Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *         <th align=left>Type</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *         <td>className</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *         <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *         <td>methodName</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *         <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *         <td>fileName</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *         <td><tt>java.lang.String</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *         <td>lineNumber</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *         <td><tt>java.lang.Integer</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *       <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *         <td>nativeMethod</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *         <td><tt>java.lang.Boolean</tt></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     *       </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *       </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     *       </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     *   </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *   <td>lockedMonitors</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     *   <td><tt>javax.management.openmbean.CompositeData[]</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     *       whose element type is the mapped type for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *       {@link MonitorInfo} as specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     *       {@link MonitorInfo#from Monitor.from} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *       <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     *       If <tt>cd</tt> does not contain this attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *       this attribute will be set to an empty array. </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *   <td>lockedSynchronizers</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *   <td><tt>javax.management.openmbean.CompositeData[]</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *       whose element type is the mapped type for
13803
889df16bef60 7193302: Remove ConstructorProperties annotation from java.lang.management.LockInfo
mchung
parents: 5506
diff changeset
   768
     *       {@link LockInfo} as specified in the {@link LockInfo#from} method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     *       <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     *       If <tt>cd</tt> does not contain this attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *       this attribute will be set to an empty array. </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @param cd <tt>CompositeData</tt> representing a <tt>ThreadInfo</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @throws IllegalArgumentException if <tt>cd</tt> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *   represent a <tt>ThreadInfo</tt> with the attributes described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *   above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @return a <tt>ThreadInfo</tt> object represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *         by <tt>cd</tt> if <tt>cd</tt> is not <tt>null</tt>;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *         <tt>null</tt> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    public static ThreadInfo from(CompositeData cd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        if (cd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (cd instanceof ThreadInfoCompositeData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            return ((ThreadInfoCompositeData) cd).getThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            return new ThreadInfo(cd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Returns an array of {@link MonitorInfo} objects, each of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * represents an object monitor currently locked by the thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * associated with this <tt>ThreadInfo</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * If no locked monitor was requested for this thread info or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * no monitor is locked by the thread, this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * @return an array of <tt>MonitorInfo</tt> objects representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *         the object monitors locked by the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    public MonitorInfo[] getLockedMonitors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        return lockedMonitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * Returns an array of {@link LockInfo} objects, each of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * represents an <a href="LockInfo.html#OwnableSynchronizer">ownable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * synchronizer</a> currently locked by the thread associated with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * this <tt>ThreadInfo</tt>.  If no locked synchronizer was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * requested for this thread info or no synchronizer is locked by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * the thread, this method will return a zero-length array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * @return an array of <tt>LockInfo</tt> objects representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *         the ownable synchronizers locked by the thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    public LockInfo[] getLockedSynchronizers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        return lockedSynchronizers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    private static final StackTraceElement[] NO_STACK_TRACE =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        new StackTraceElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
}