use of java.lang.management.ThreadMXBean in project ignite by apache.
the class IgniteUtils method dumpThreads.
/**
* Performs thread dump and prints all available info to the given log.
*
* @param log Logger.
*/
public static void dumpThreads(@Nullable IgniteLogger log) {
ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
final Set<Long> deadlockedThreadsIds = getDeadlockedThreadIds(mxBean);
if (deadlockedThreadsIds.size() == 0)
warn(log, "No deadlocked threads detected.");
else
warn(log, "Deadlocked threads detected (see thread dump below) " + "[deadlockedThreadsCnt=" + deadlockedThreadsIds.size() + ']');
ThreadInfo[] threadInfos = mxBean.dumpAllThreads(mxBean.isObjectMonitorUsageSupported(), mxBean.isSynchronizerUsageSupported());
GridStringBuilder sb = new GridStringBuilder("Thread dump at ").a(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss z").format(new Date(U.currentTimeMillis()))).a(NL);
for (ThreadInfo info : threadInfos) {
printThreadInfo(info, sb, deadlockedThreadsIds);
sb.a(NL);
if (info.getLockedSynchronizers() != null && info.getLockedSynchronizers().length > 0) {
printSynchronizersInfo(info.getLockedSynchronizers(), sb);
sb.a(NL);
}
}
sb.a(NL);
warn(log, sb.toString());
}
use of java.lang.management.ThreadMXBean in project drools by kiegroup.
the class TestStatusListener method writeThreadDump.
private synchronized void writeThreadDump() throws IOException {
final ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
for (final ThreadInfo ti : threadMxBean.dumpAllThreads(true, true)) {
writer.write(ti.toString());
if (ti.getStackTrace().length > 8) {
writer.write("full stacktrace:\n");
writer.write(fullStackTrace(ti));
writer.write("\n");
}
}
writer.newLine();
writer.flush();
}
use of java.lang.management.ThreadMXBean in project scheduling by ow2-proactive.
the class TimedOutTestsListener method buildDeadlockInfo.
private static String buildDeadlockInfo() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadBean.findMonitorDeadlockedThreads();
if (threadIds != null && threadIds.length > 0) {
StringBuilder sb = new StringBuilder();
ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
for (ThreadInfo ti : infos) {
printThreadInfo(ti, sb);
printLockInfo(ti.getLockedSynchronizers(), sb);
sb.append(System.getProperty("line.separator"));
}
return sb.toString();
} else {
return null;
}
}
use of java.lang.management.ThreadMXBean in project Payara by payara.
the class HoggingThreadsHealthCheck method doCheck.
@Override
public HealthCheckResult doCheck() {
if (!getOptions().isEnabled()) {
return null;
}
HealthCheckResult result = new HealthCheckResult();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
if (!threadBean.isCurrentThreadCpuTimeSupported()) {
result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CHECK_ERROR, "JVM implementation or OS does" + " not support getting CPU times"));
return result;
}
final long[] ids = threadBean.getAllThreadIds();
for (long id : ids) {
if (id == Thread.currentThread().getId())
continue;
final long c = threadBean.getThreadCpuTime(id);
final long u = threadBean.getThreadUserTime(id);
ThreadInfo threadInfo = threadBean.getThreadInfo(id);
if (c == -1 || u == -1)
continue;
ThreadTimes times = threadTimes.get(id);
if (times == null) {
times = new ThreadTimes();
times.setId(id);
times.setName(threadInfo.getThreadName());
times.setStartCpuTime(c);
times.setEndCpuTime(c);
times.setStartUserTime(u);
times.setEndUserTime(u);
threadTimes.put(id, times);
} else {
times.setStartCpuTime(times.getEndCpuTime());
times.setStartUserTime(times.getEndUserTime());
times.setEndCpuTime(c);
times.setEndUserTime(u);
long checkTime = getOptions().getUnit().toMillis(getOptions().getTime());
long duration = times.getEndCpuTime() - times.getStartCpuTime();
double percentage = ((double) (TimeUnit.NANOSECONDS.toMillis(duration)) / (double) (checkTime)) * 100;
if (percentage > options.getThresholdPercentage()) {
if (times.getRetryCount() == 0) {
times.setInitialStartCpuTime(System.nanoTime());
times.setInitialStartUserTime(System.nanoTime());
}
if (times.getRetryCount() >= options.getRetryCount()) {
result.add(new HealthCheckResultEntry(HealthCheckResultStatus.CRITICAL, "Thread with <id-name>: " + id + "-" + times.getName() + " is a hogging thread for the last " + prettyPrintDuration(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - times.getInitialStartCpuTime())) + "\n" + prettyPrintStackTrace(threadInfo.getStackTrace())));
}
times.setRetryCount(times.getRetryCount() + 1);
}
}
}
return result;
}
use of java.lang.management.ThreadMXBean in project jdk8u_jdk by JetBrains.
the class JvmThreadingImpl method checkJvmThreadCpuTimeMonitoring.
/**
* Checker for the "JvmThreadCpuTimeMonitoring" variable.
*/
public void checkJvmThreadCpuTimeMonitoring(EnumJvmThreadCpuTimeMonitoring x) throws SnmpStatusException {
//Can't be set externaly to unsupported state.
if (JvmThreadCpuTimeMonitoringUnsupported.intValue() == x.intValue()) {
log.debug("checkJvmThreadCpuTimeMonitoring", "Try to set to illegal unsupported value");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
if ((JvmThreadCpuTimeMonitoringEnabled.intValue() == x.intValue()) || (JvmThreadCpuTimeMonitoringDisabled.intValue() == x.intValue())) {
// The value is a valid value. But is the feature supported?
ThreadMXBean mbean = getThreadMXBean();
if (mbean.isThreadCpuTimeSupported())
return;
// Not supported.
log.debug("checkJvmThreadCpuTimeMonitoring", "Unsupported operation, can't set state");
throw new SnmpStatusException(SnmpDefinitions.snmpRspInconsistentValue);
}
// Unknown value.
log.debug("checkJvmThreadCpuTimeMonitoring", "unknown enum value ");
throw new SnmpStatusException(SnmpDefinitions.snmpRspWrongValue);
}
Aggregations