Search in sources :

Example 41 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jgnash by ccavanaugh.

the class EventDispatchThreadHangMonitor method checkForDeadlock.

private static void checkForDeadlock() {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    long[] threadIds = threadBean.findMonitorDeadlockedThreads();
    if (threadIds == null) {
        return;
    }
    Log.warn("deadlock detected involving the following threads:");
    ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
    for (ThreadInfo info : threadInfos) {
        Log.warn("Thread #" + info.getThreadId() + " " + info.getThreadName() + " (" + info.getThreadState() + ") waiting on " + info.getLockName() + " held by " + info.getLockOwnerName() + stackTraceToString(info.getStackTrace()));
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo)

Example 42 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project Gargoyle by callakrsos.

the class CPUUsageTest method showThreadBean.

public void showThreadBean() {
    ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
    long[] ids = tbean.getAllThreadIds();
    System.out.println("Thread Count: " + tbean.getThreadCount());
    for (long id : ids) {
        System.out.println("Thread CPU Time(" + id + ")" + tbean.getThreadCpuTime(id));
        System.out.println("Thread User Time(" + id + ")" + tbean.getThreadCpuTime(id));
    }
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Example 43 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.

the class JvmThreadingImpl method checkJvmThreadContentionMonitoring.

/**
     * Checker for the "JvmThreadContentionMonitoring" variable.
     */
public void checkJvmThreadContentionMonitoring(EnumJvmThreadContentionMonitoring x) throws SnmpStatusException {
    //Can't be set externaly to unsupported state.
    if (JvmThreadContentionMonitoringUnsupported.intValue() == x.intValue()) {
        log.debug("checkJvmThreadContentionMonitoring", "Try to set to illegal unsupported value");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
    }
    if ((JvmThreadContentionMonitoringEnabled.intValue() == x.intValue()) || (JvmThreadContentionMonitoringDisabled.intValue() == x.intValue())) {
        // The value is valid, but is the feature supported ?
        ThreadMXBean mbean = getThreadMXBean();
        if (mbean.isThreadContentionMonitoringSupported())
            return;
        log.debug("checkJvmThreadContentionMonitoring", "Unsupported operation, can't set state");
        throw new SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
    }
    log.debug("checkJvmThreadContentionMonitoring", "Try to set to unknown value");
    throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ThreadMXBean(java.lang.management.ThreadMXBean)

Example 44 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.

the class JvmThreadInstanceEntryImpl method getJvmThreadInstBlockTimeMs.

/**
     * Getter for the "JvmThreadInstBlockTimeMs" variable.
     */
public Long getJvmThreadInstBlockTimeMs() throws SnmpStatusException {
    long l = 0;
    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
    if (tmb.isThreadContentionMonitoringSupported()) {
        l = info.getBlockedTime();
        //Monitoring is disabled
        if (l == -1)
            l = 0;
    }
    return new Long(l);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Example 45 with ThreadMXBean

use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.

the class JvmThreadInstanceEntryImpl method getJvmThreadInstCpuTimeNs.

/**
     * Getter for the "JvmThreadInstCpuTimeNs" variable.
     */
public Long getJvmThreadInstCpuTimeNs() throws SnmpStatusException {
    long l = 0;
    final ThreadMXBean tmb = JvmThreadingImpl.getThreadMXBean();
    try {
        if (tmb.isThreadCpuTimeSupported()) {
            l = tmb.getThreadCpuTime(info.getThreadId());
            log.debug("getJvmThreadInstCpuTimeNs", "Cpu time ns : " + l);
            //Cpu time measurement is disabled or the id is not valid.
            if (l == -1)
                l = 0;
        }
    } catch (UnsatisfiedLinkError e) {
        // XXX Revisit: catch TO BE EVENTUALLY REMOVED
        log.debug("getJvmThreadInstCpuTimeNs", "Operation not supported: " + e);
    }
    return new Long(l);
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean)

Aggregations

ThreadMXBean (java.lang.management.ThreadMXBean)105 ThreadInfo (java.lang.management.ThreadInfo)56 HashMap (java.util.HashMap)9 RuntimeMXBean (java.lang.management.RuntimeMXBean)8 MemoryMXBean (java.lang.management.MemoryMXBean)7 IOException (java.io.IOException)6 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)4 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)4 MemoryUsage (java.lang.management.MemoryUsage)4 HealthCheckResultEntry (fish.payara.notification.healthcheck.HealthCheckResultEntry)3 HealthCheckResult (fish.payara.nucleus.healthcheck.HealthCheckResult)3 LockInfo (java.lang.management.LockInfo)3 ManagementFactory (java.lang.management.ManagementFactory)3 MonitorInfo (java.lang.management.MonitorInfo)3