List of usage examples for java.lang.management ManagementFactory getThreadMXBean
public static ThreadMXBean getThreadMXBean()
From source file:ro.nextreports.server.web.debug.InfoUtil.java
public static List<Info> getGeneralJVMInfo() { List<Info> infos = new ArrayList<Info>(); RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); infos.add(new Info("uptime", "" + Duration.milliseconds(runtimeBean.getUptime()).toString())); infos.add(new Info("name", runtimeBean.getName())); infos.add(new Info("pid", runtimeBean.getName().split("@")[0])); OperatingSystemMXBean systemBean = ManagementFactory.getOperatingSystemMXBean(); infos.add(new Info("os name", "" + systemBean.getName())); infos.add(new Info("os version", "" + systemBean.getVersion())); infos.add(new Info("system load average", "" + systemBean.getSystemLoadAverage())); infos.add(new Info("available processors", "" + systemBean.getAvailableProcessors())); ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); infos.add(new Info("thread count", "" + threadBean.getThreadCount())); infos.add(new Info("peak thread count", "" + threadBean.getPeakThreadCount())); MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean(); infos.add(new Info("heap memory used", FileUtils.byteCountToDisplaySize(memoryBean.getHeapMemoryUsage().getUsed()))); infos.add(new Info("non-heap memory used", FileUtils.byteCountToDisplaySize(memoryBean.getNonHeapMemoryUsage().getUsed()))); return infos; }
From source file:org.asoem.greyfish.impl.environment.MyThreadSizeCalculator.java
@Override protected long getCurrentThreadCPUTime() { return ManagementFactory.getThreadMXBean().getCurrentThreadCpuTime(); }
From source file:DeadLockDetector.java
/** * Create new DeadLockDetector with given values. * /*from w w w . ja v a2s . c o m*/ * @param sleepTime * @param doWhenDL */ public DeadLockDetector(int sleepTime, byte doWhenDL) { super("DeadLockDetector"); this.sleepTime = sleepTime * 1000; this.tmx = ManagementFactory.getThreadMXBean(); this.doWhenDL = doWhenDL; }
From source file:com.amazonaws.client.metrics.support.JmxInfoProviderSupport.java
@Override public int getThreadCount() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.getThreadCount(); }
From source file:com.amazonaws.client.metrics.support.JmxInfoProviderSupport.java
@Override public int getDaemonThreadCount() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.getDaemonThreadCount(); }
From source file:com.l2jfree.lang.L2Thread.java
public static List<String> getStats(Thread t) { List<String> list = new FastList<String>(); list.add(t.toString() + " - ID: " + t.getId()); list.add(" * State: " + t.getState()); list.add(" * Alive: " + t.isAlive()); list.add(" * Daemon: " + t.isDaemon()); list.add(" * Interrupted: " + t.isInterrupted()); for (ThreadInfo info : ManagementFactory.getThreadMXBean().getThreadInfo(new long[] { t.getId() }, true, true)) {//w w w. ja va2s .c o m for (MonitorInfo monitorInfo : info.getLockedMonitors()) { list.add("=========="); list.add(" * Locked monitor: " + monitorInfo); list.add("\t[" + monitorInfo.getLockedStackDepth() + ".]: at " + monitorInfo.getLockedStackFrame()); } for (LockInfo lockInfo : info.getLockedSynchronizers()) { list.add("=========="); list.add(" * Locked synchronizer: " + lockInfo); } list.add("=========="); for (StackTraceElement trace : info.getStackTrace()) list.add("\tat " + trace); } return list; }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
@Override public void appendInformation(InformationStringBuilder infoCollector) { osInfo(ManagementFactory.getOperatingSystemMXBean(), infoCollector); runtimeInfo(ManagementFactory.getRuntimeMXBean(), infoCollector); gcInfo(ManagementFactory.getGarbageCollectorMXBeans(), infoCollector); memoryInfo(ManagementFactory.getMemoryMXBean(), infoCollector); poolInfo(infoCollector);//from w w w. j av a 2 s . c o m threadInfo(ManagementFactory.getThreadMXBean(), infoCollector); }
From source file:com.amazonaws.client.metrics.support.JmxInfoProviderSupport.java
@Override public int getPeakThreadCount() { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); return threadMXBean.getPeakThreadCount(); }
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./*from w ww .j a v a 2 s . c om*/ * * @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:com.twosigma.beakerx.kernel.magic.command.functionality.TimeMagicCommand.java
public MagicCommandOutput time(String codeToExecute, Message message, int executionCount, boolean showResult) { CompletableFuture<TimeMeasureData> compileTime = new CompletableFuture<>(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); long currentThreadId = Thread.currentThread().getId(); Long startWallTime = System.nanoTime(); Long startCpuTotalTime = threadMXBean.getCurrentThreadCpuTime(); Long startUserTime = threadMXBean.getCurrentThreadUserTime(); SimpleEvaluationObject simpleEvaluationObject = createSimpleEvaluationObject(codeToExecute, kernel, message, executionCount);/*from w ww. ja va 2 s . c om*/ if (!showResult) { simpleEvaluationObject.noResult(); } TryResult either = kernel.executeCode(codeToExecute, simpleEvaluationObject); Long endWallTime = System.nanoTime(); Long endCpuTotalTime = threadMXBean.getThreadCpuTime(currentThreadId); Long endUserTime = threadMXBean.getThreadUserTime(currentThreadId); compileTime.complete(new TimeMeasureData(endCpuTotalTime - startCpuTotalTime, endUserTime - startUserTime, endWallTime - startWallTime)); String messageInfo = "CPU times: user %s, sys: %s, total: %s \nWall Time: %s\n"; try { TimeMeasureData timeMeasuredData = compileTime.get(); return new MagicCommandOutput(MagicCommandOutput.Status.OK, String.format(messageInfo, format(timeMeasuredData.getCpuUserTime()), format(timeMeasuredData.getCpuTotalTime() - timeMeasuredData.getCpuUserTime()), format(timeMeasuredData.getCpuTotalTime()), format(timeMeasuredData.getWallTime())), either, simpleEvaluationObject); } catch (InterruptedException | ExecutionException e) { return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during measuring time for your statement."); } }