jdk/src/share/demo/management/FullThreadDump/ThreadMonitor.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2004-2005 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *   - Neither the name of Sun Microsystems nor the names of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import static java.lang.management.ManagementFactory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.lang.management.ThreadMXBean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.lang.management.ThreadInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.lang.management.LockInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.management.MonitorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Example of using the java.lang.management API to dump stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * and to perform deadlock detection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @author  Mandy Chung
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class ThreadMonitor {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private MBeanServerConnection server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    private ThreadMXBean tmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private ObjectName objname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // default - JDK 6+ VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private String findDeadlocksMethodName = "findDeadlockedThreads";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private boolean canDumpLocks = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Constructs a ThreadMonitor object to get thread information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * in a remote JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public ThreadMonitor(MBeanServerConnection server) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
       this.server = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
       this.tmbean = newPlatformMXBeanProxy(server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                            THREAD_MXBEAN_NAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                            ThreadMXBean.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
       try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
           objname = new ObjectName(THREAD_MXBEAN_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } catch (MalformedObjectNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            // should not reach here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            InternalError ie = new InternalError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            ie.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw ie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
       parseMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Constructs a ThreadMonitor object to get thread information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * in the local JVM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public ThreadMonitor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        this.tmbean = getThreadMXBean();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Prints the thread dump information to System.out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public void threadDump() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (canDumpLocks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (tmbean.isObjectMonitorUsageSupported() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                tmbean.isSynchronizerUsageSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                // Print lock info if both object monitor usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                // and synchronizer usage are supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                // This sample code can be modified to handle if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // either monitor usage or synchronizer usage is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                dumpThreadInfoWithLocks();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            dumpThreadInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private void dumpThreadInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
       System.out.println("Full Java thread dump");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
       long[] tids = tmbean.getAllThreadIds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
       ThreadInfo[] tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
       for (ThreadInfo ti : tinfos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
           printThreadInfo(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Prints the thread dump information with locks info to System.out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private void dumpThreadInfoWithLocks() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
       System.out.println("Full Java thread dump with locks info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
       ThreadInfo[] tinfos = tmbean.dumpAllThreads(true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
       for (ThreadInfo ti : tinfos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
           printThreadInfo(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
           LockInfo[] syncs = ti.getLockedSynchronizers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
           printLockInfo(syncs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
       System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private static String INDENT = "    ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private void printThreadInfo(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
       // print thread information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
       printThread(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
       // print stack trace with locks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
       StackTraceElement[] stacktrace = ti.getStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
       MonitorInfo[] monitors = ti.getLockedMonitors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
       for (int i = 0; i < stacktrace.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
           StackTraceElement ste = stacktrace[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
           System.out.println(INDENT + "at " + ste.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
           for (MonitorInfo mi : monitors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
               if (mi.getLockedStackDepth() == i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                   System.out.println(INDENT + "  - locked " + mi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
       System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private void printThread(ThreadInfo ti) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
       StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                            " Id=" + ti.getThreadId() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                                            " in " + ti.getThreadState());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
       if (ti.getLockName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
           sb.append(" on lock=" + ti.getLockName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
       if (ti.isSuspended()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
           sb.append(" (suspended)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
       if (ti.isInNative()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
           sb.append(" (running in native)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
       System.out.println(sb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
       if (ti.getLockOwnerName() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            System.out.println(INDENT + " owned by " + ti.getLockOwnerName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                               " Id=" + ti.getLockOwnerId());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    private void printMonitorInfo(ThreadInfo ti, MonitorInfo[] monitors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
       System.out.println(INDENT + "Locked monitors: count = " + monitors.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
       for (MonitorInfo mi : monitors) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
           System.out.println(INDENT + "  - " + mi + " locked at ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
           System.out.println(INDENT + "      " + mi.getLockedStackDepth() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                              " " + mi.getLockedStackFrame());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    private void printLockInfo(LockInfo[] locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
       System.out.println(INDENT + "Locked synchronizers: count = " + locks.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
       for (LockInfo li : locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
           System.out.println(INDENT + "  - " + li);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
       System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Checks if any threads are deadlocked. If any, print
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * the thread dump information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public boolean findDeadlock() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
       long[] tids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
       if (findDeadlocksMethodName.equals("findDeadlockedThreads") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
               tmbean.isSynchronizerUsageSupported()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
           tids = tmbean.findDeadlockedThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
           if (tids == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
               return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
           System.out.println("Deadlock found :-");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
           ThreadInfo[] infos = tmbean.getThreadInfo(tids, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
           for (ThreadInfo ti : infos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
               printThreadInfo(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
               printLockInfo(ti.getLockedSynchronizers());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
               System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
       } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
           tids = tmbean.findMonitorDeadlockedThreads();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
           if (tids == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
               return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
           ThreadInfo[] infos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
           for (ThreadInfo ti : infos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
               // print thread information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
               printThreadInfo(ti);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
       return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private void parseMBeanInfo() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            MBeanOperationInfo[] mopis = server.getMBeanInfo(objname).getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // look for findDeadlockedThreads operations;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            for (MBeanOperationInfo op : mopis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                if (op.getName().equals(findDeadlocksMethodName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                // if findDeadlockedThreads operation doesn't exist,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                // the target VM is running on JDK 5 and details about
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                // synchronizers and locks cannot be dumped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                findDeadlocksMethodName = "findMonitorDeadlockedThreads";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                canDumpLocks = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        } catch (IntrospectionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            InternalError ie = new InternalError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            ie.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            throw ie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } catch (InstanceNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            InternalError ie = new InternalError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            ie.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            throw ie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } catch (ReflectionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            InternalError ie = new InternalError(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            ie.initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw ie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
}