Example usage for java.lang.management ThreadMXBean isSynchronizerUsageSupported

List of usage examples for java.lang.management ThreadMXBean isSynchronizerUsageSupported

Introduction

In this page you can find the example usage for java.lang.management ThreadMXBean isSynchronizerUsageSupported.

Prototype

public boolean isSynchronizerUsageSupported();

Source Link

Document

Tests if the Java virtual machine supports monitoring of ownable synchronizer usage.

Usage

From source file:Main.java

/** Returns all stack traces, including lock info. */
public static String getAllStackTraces() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    boolean monitor = threadMXBean.isObjectMonitorUsageSupported();
    boolean sync = threadMXBean.isSynchronizerUsageSupported();
    ThreadInfo[] allThreadInfo = threadMXBean.dumpAllThreads(monitor, sync);
    StringBuilder sb = new StringBuilder("Stack Trace Report:\n");
    buildTrace(allThreadInfo, sb);/*from ww w.  ja  va 2  s  .c o  m*/
    return sb.toString();
}

From source file:Main.java

/**
 * Get the thread info for the thread with the given ID.
 * A null is returned if no such thread info is found.
 *
 * @param   id   the thread ID to search for
 * @return      the thread info, or null if not found
 * @throws   IllegalArgumentException/*w  w w  . j  a v a 2 s. c om*/
 *         if id <= 0
 */
public static ThreadInfo getThreadInfo(final long id) {
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();

    // Get thread info with lock info, when available.
    if (!thbean.isObjectMonitorUsageSupported() || !thbean.isSynchronizerUsageSupported())
        return thbean.getThreadInfo(id);

    final ThreadInfo[] infos = thbean.getThreadInfo(new long[] { id }, true, true);
    if (infos.length == 0)
        return null;
    return infos[0];
}

From source file:Main.java

/**
 * Get the thread info for the thread with the given ID. A null is returned
 * if no such thread info is found./* ww w .j a v  a 2s  .  co  m*/
 * 
 * @param id
 *        the thread ID to search for
 * @return the thread info, or null if not found
 * @throws IllegalArgumentException
 *         if id <= 0
 */
public static ThreadInfo getThreadInfo(final long id) {
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();

    // Get thread info with lock info, when available.
    if (!thbean.isObjectMonitorUsageSupported() || !thbean.isSynchronizerUsageSupported()) {
        return thbean.getThreadInfo(id);
    }

    final ThreadInfo[] infos = thbean.getThreadInfo(new long[] { id }, true, true);
    if (infos.length == 0)
        return null;
    return infos[0];
}

From source file:Main.java

/**
 * Get a list of all thread info objects.  Since there is
 * always at least one thread running, there is always at
 * least one thread info object.  This method never returns
 * a null or empty array.// w  ww.  j a  v  a2  s.  co m
 *
 * @return      an array of thread infos
 */
public static ThreadInfo[] getAllThreadInfos() {
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    final long[] ids = thbean.getAllThreadIds();

    // Get thread info with lock info, when available.
    ThreadInfo[] infos;
    if (!thbean.isObjectMonitorUsageSupported() || !thbean.isSynchronizerUsageSupported())
        infos = thbean.getThreadInfo(ids);
    else
        infos = thbean.getThreadInfo(ids, true, true);

    // Clean nulls from array if threads have died.
    final ThreadInfo[] notNulls = new ThreadInfo[infos.length];
    int nNotNulls = 0;
    for (ThreadInfo info : infos)
        if (info != null)
            notNulls[nNotNulls++] = info;
    if (nNotNulls == infos.length)
        return infos; // Original had no nulls
    return java.util.Arrays.copyOf(notNulls, nNotNulls);
}

From source file:Main.java

/**
 * Get a list of all thread info objects. Since there is always at least one
 * thread running, there is always at least one thread info object. This
 * method never returns a null or empty array.
 * /*from   www  . j a v  a  2s.c  o  m*/
 * @return an array of thread infos
 */
public static ThreadInfo[] getAllThreadInfos() {
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    final long[] ids = thbean.getAllThreadIds();

    // Get thread info with lock info, when available.
    ThreadInfo[] infos;
    if (!thbean.isObjectMonitorUsageSupported() || !thbean.isSynchronizerUsageSupported()) {
        infos = thbean.getThreadInfo(ids);
    } else {
        infos = thbean.getThreadInfo(ids, true, true);
    }

    // Clean nulls from array if threads have died.
    final ThreadInfo[] notNulls = new ThreadInfo[infos.length];
    int nNotNulls = 0;
    for (ThreadInfo info : infos) {
        if (info != null) {
            notNulls[nNotNulls++] = info;
        }
    }
    if (nNotNulls == infos.length)
        return infos; // Original had no nulls
    return java.util.Arrays.copyOf(notNulls, nNotNulls);
}

From source file:net.bull.javamelody.internal.model.JavaInformations.java

private static long[] getDeadlockedThreads(ThreadMXBean threadBean) {
    final long[] deadlockedThreads;
    if (threadBean.isSynchronizerUsageSupported()) {
        deadlockedThreads = threadBean.findDeadlockedThreads();
    } else {/*from  w  w  w  . jav a2  s .c  o  m*/
        deadlockedThreads = threadBean.findMonitorDeadlockedThreads();
    }
    if (deadlockedThreads != null) {
        Arrays.sort(deadlockedThreads);
    }
    return deadlockedThreads;
}

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

@Override
ThreadInfo[] getThreadInfos(ThreadMXBean bean) {
    return bean.dumpAllThreads(bean.isObjectMonitorUsageSupported(), bean.isSynchronizerUsageSupported());
}

From source file:hudson.Functions.java

@IgnoreJRERequirement
public static ThreadInfo[] getThreadInfos() {
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    return mbean.getThreadInfo(mbean.getAllThreadIds(), mbean.isObjectMonitorUsageSupported(),
            mbean.isSynchronizerUsageSupported());
}

From source file:org.fluentd.jvmwatcher.proxy.JvmClientProxy.java

/**
 * @return//from  ww  w. ja va2 s  .c om
 * @throws IOException
 */
public long[] findDeadlockedThreads() throws IOException {
    ThreadMXBean threadMx = getThreadMXBean();
    if (this.supportsLockUsage_ && threadMx.isSynchronizerUsageSupported()) {
        return threadMx.findDeadlockedThreads();
    } else {
        return threadMx.findMonitorDeadlockedThreads();
    }
}