Example usage for java.lang.management LockInfo getClassName

List of usage examples for java.lang.management LockInfo getClassName

Introduction

In this page you can find the example usage for java.lang.management LockInfo getClassName.

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class of the lock object.

Usage

From source file:Main.java

private static String threadLockedSynchronizers(ThreadInfo threadInfo) {
    final String NO_SYNCH_INFO = "no locked synchronizers information available\n";
    if (null == threadInfo) {
        return NO_SYNCH_INFO;
    }/*from ww w. j  a  va2s. co  m*/
    try {
        final LockInfo[] lockInfos = threadInfo.getLockedSynchronizers();
        if (lockInfos.length > 0) {
            final StringBuffer lockedSynchBuff = new StringBuffer();
            lockedSynchBuff.append("\nLocked Synchronizers: \n");
            for (final LockInfo lockInfo : lockInfos) {
                lockedSynchBuff.append(lockInfo.getClassName()).append(" <")
                        .append(lockInfo.getIdentityHashCode()).append("> \n");
            }
            return lockedSynchBuff.append("\n").toString();
        } else {
            return "";
        }
    } catch (final Exception e) {
        return NO_SYNCH_INFO;
    }
}

From source file:Main.java

private static void formatLock(final StringBuilder sb, final LockInfo lock) {
    sb.append("<").append(lock.getIdentityHashCode()).append("> (a ");
    sb.append(lock.getClassName()).append(")");
}

From source file:com.thoughtworks.go.server.service.support.ThreadInformationProvider.java

private LinkedHashMap<String, Object> asJSON(LockInfo lockInfo) {
    LinkedHashMap<String, Object> lockedOn = new LinkedHashMap<>();
    if (lockInfo != null) {
        lockedOn.put("Class", lockInfo.getClassName());
        lockedOn.put("IdentityHashCode", lockInfo.getIdentityHashCode());
    }//  w ww  .  ja v a 2 s. c om
    return lockedOn;
}

From source file:com.workplacesystems.utilsj.ThreadDumperJdk16.java

private void formatLock(LockInfo lockInfo, String message, StringBuffer buffer) {
    buffer.append("        - ");
    if (message != null && !message.equals("")) {
        buffer.append(message);/*from  www .j a va 2  s .co  m*/
        buffer.append(" ");
    }
    buffer.append("<");
    buffer.append(Integer.toHexString(lockInfo.getIdentityHashCode()));
    buffer.append("> (a ");
    buffer.append(lockInfo.getClassName());
    buffer.append(")");
}

From source file:org.ScripterRon.JavaBitcoin.RpcHandler.java

/**
 * Process 'getstacktraces' request/*from   ww  w . ja va 2s  .  c  o  m*/
 *
 * Response parameters:
 *   locks   - An array of lock objects for locks with waiters
 *   threads - An array of thread objects
 *
 * Lock object:
 *   name   - Lock class name
 *   hash   - Lock identity hash code
 *   thread - Identifier of thread holding the lock
 *
 * Monitor object:
 *   name    - Monitor class name
 *   hash    - Monitor identity hash
 *   depth   - Stack depth where monitor locked
 *   trace   - Stack element where monitor locked
 *
 * Thread object:
 *   blocked - Lock object if thread is waiting on a lock
 *   id      - Thread identifier
 *   locks   - Array of monitor objects for locks held by this thread
 *   name    - Thread name
 *   state   - Thread state
 *   trace   - Array of stack trace elements
 *
 * @return                              Response as a JSONObject
 */
private JSONObject getStackTraces() {
    JSONArray threadsJSON = new JSONArray();
    JSONArray locksJSON = new JSONArray();
    ThreadMXBean tmxBean = ManagementFactory.getThreadMXBean();
    boolean tmxMI = tmxBean.isObjectMonitorUsageSupported();
    ThreadInfo[] tList = tmxBean.dumpAllThreads(tmxMI, false);
    //
    // Generate the response
    //
    for (ThreadInfo tInfo : tList) {
        JSONObject threadJSON = new JSONObject();
        //
        // General thread information
        //
        threadJSON.put("id", tInfo.getThreadId());
        threadJSON.put("name", tInfo.getThreadName());
        threadJSON.put("state", tInfo.getThreadState().toString());
        //
        // Gather lock usage
        //
        if (tmxMI) {
            MonitorInfo[] mList = tInfo.getLockedMonitors();
            if (mList.length > 0) {
                JSONArray monitorsJSON = new JSONArray();
                for (MonitorInfo mInfo : mList) {
                    JSONObject lockJSON = new JSONObject();
                    lockJSON.put("name", mInfo.getClassName());
                    lockJSON.put("hash", mInfo.getIdentityHashCode());
                    lockJSON.put("depth", mInfo.getLockedStackDepth());
                    lockJSON.put("trace", mInfo.getLockedStackFrame().toString());
                    monitorsJSON.add(lockJSON);
                }
                threadJSON.put("locks", monitorsJSON);
            }
            if (tInfo.getThreadState() == Thread.State.BLOCKED) {
                LockInfo lInfo = tInfo.getLockInfo();
                if (lInfo != null) {
                    JSONObject lockJSON = new JSONObject();
                    lockJSON.put("name", lInfo.getClassName());
                    lockJSON.put("hash", lInfo.getIdentityHashCode());
                    lockJSON.put("thread", tInfo.getLockOwnerId());
                    threadJSON.put("blocked", lockJSON);
                    boolean addLock = true;
                    for (Object lock : locksJSON) {
                        if (((String) ((JSONObject) lock).get("name")).equals(lInfo.getClassName())) {
                            addLock = false;
                            break;
                        }
                    }
                    if (addLock)
                        locksJSON.add(lockJSON);
                }
            }
        }
        //
        // Add the stack trace
        //
        StackTraceElement[] elements = tInfo.getStackTrace();
        JSONArray traceJSON = new JSONArray();
        for (StackTraceElement element : elements)
            traceJSON.add(element.toString());
        threadJSON.put("trace", traceJSON);
        //
        // Add the thread to the response
        //
        threadsJSON.add(threadJSON);
    }
    //
    // Return the response
    //
    JSONObject response = new JSONObject();
    response.put("threads", threadsJSON);
    response.put("locks", locksJSON);
    return response;
}