java.lang.management.ThreadMXBean Java Examples

The following examples show how to use java.lang.management.ThreadMXBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: jdk8u-dev-jdk   Author: frohoff   File: ConnectorStopDeadlockTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example #2
Source Project: lutece-core   Author: lutece-platform   File: ThreadLauncherDaemonTest.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void dumpStateWhileWaiting( long lWait ) throws InterruptedException
{
    // wait for the daemon to have a chance to try running
    Thread.sleep( lWait );
    final StringBuilder dump = new StringBuilder( );
    final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean( );
    final ThreadInfo[ ] threadInfos = threadMXBean.getThreadInfo( threadMXBean.getAllThreadIds( ), 100 );
    for ( ThreadInfo threadInfo : threadInfos )
    {
        dump.append( '"' );
        dump.append( threadInfo.getThreadName( ) );
        dump.append( "\" " );
        final Thread.State state = threadInfo.getThreadState( );
        dump.append( "\n   java.lang.Thread.State: " );
        dump.append( state );
        final StackTraceElement[ ] stackTraceElements = threadInfo.getStackTrace( );
        for ( final StackTraceElement stackTraceElement : stackTraceElements )
        {
            dump.append( "\n        at " );
            dump.append( stackTraceElement );
        }
        dump.append( "\n\n" );
    }
    AppLogService.info( "Current state : " + dump );
}
 
Example #3
Source Project: weblaf   Author: mgarin   File: DebugUtils.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns deadlocked threads stack trace.
 *
 * @return deadlocked threads stack trace
 */
@NotNull
public static String getDeadlockStackTrace ()
{
    final ThreadMXBean bean = ManagementFactory.getThreadMXBean ();
    final long[] threadIds = bean.findDeadlockedThreads ();
    final StringBuilder stackTrace = new StringBuilder ();
    if ( threadIds != null )
    {
        final ThreadInfo[] infos = bean.getThreadInfo ( threadIds );
        for ( final ThreadInfo info : infos )
        {
            final StackTraceElement[] stack = info.getStackTrace ();
            stackTrace.append ( ExceptionUtils.getStackTrace ( stack ) );
            stackTrace.append ( info != infos[ infos.length - 1 ] ? "\n" : "" );
        }
    }
    return stackTrace.toString ();
}
 
Example #4
Source Project: couchbase-jvm-core   Author: couchbase   File: DefaultCoreEnvironmentTest.java    License: Apache License 2.0 6 votes vote down vote up
private static Set<String> getCouchbaseThreads() {
    final ThreadMXBean threadManager = ManagementFactory.getThreadMXBean();
    final ThreadInfo[] threads = threadManager.getThreadInfo(threadManager.getAllThreadIds());

    final Set<String> result = new HashSet<>();
    for (ThreadInfo t : threads) {
        if (t == null || t.getThreadName() == null || t.getThreadState() == Thread.State.TERMINATED) {
            continue; // thread already dead, or anonymous (not one of ours)
        }
        String name = t.getThreadName();
        if (name.startsWith("cb-") || name.contains("Rx")) {
            result.add(t.getThreadId() + ":" +t.getThreadName());
        }
    }
    return result;
}
 
Example #5
Source Project: Jpom   Author: jiangzeyin   File: JvmUtil.java    License: MIT License 6 votes vote down vote up
/**
 * 获取指定程序的线程信息
 *
 * @param jpomTag jpomTag
 * @return 没有运行或者获取数据
 * @throws Exception 异常
 * @see ThreadMXBean
 */
public static ThreadMXBean getThreadMXBean(String jpomTag) throws Exception {
    VirtualMachine virtualMachine = JvmUtil.getVirtualMachine(jpomTag);
    if (virtualMachine == null) {
        return null;
    }
    try {
        JMXServiceURL url = getJMXServiceURL(virtualMachine);
        if (url == null) {
            return null;
        }
        JMXConnector jmxConnector = JMXConnectorFactory.connect(url, null);
        MBeanServerConnection mBeanServerConnection = jmxConnector.getMBeanServerConnection();
        return ManagementFactory.newPlatformMXBeanProxy(mBeanServerConnection, ManagementFactory.THREAD_MXBEAN_NAME, ThreadMXBean.class);
    } finally {
        virtualMachine.detach();
    }
}
 
Example #6
Source Project: hottub   Author: dsrg-uoft   File: ConnectorStopDeadlockTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example #7
Source Project: openhab-core   Author: openhab   File: SafeCallerImplTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static String createThreadDump(String threadNamePrefix) {
    final StringBuilder sb = new StringBuilder();
    final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadMXBean.getAllThreadIds(), Integer.MAX_VALUE)) {
        if (!threadInfo.getThreadName().startsWith(threadNamePrefix)) {
            continue;
        }
        sb.append("\"");
        sb.append(threadInfo.getThreadName());
        sb.append("\" ");
        sb.append(State.class.getName());
        sb.append(": ");
        sb.append(threadInfo.getThreadState());
        for (final StackTraceElement stackTraceElement : threadInfo.getStackTrace()) {
            sb.append("\n    at ");
            sb.append(stackTraceElement);
        }
    }
    return sb.toString();
}
 
Example #8
Source Project: swift-k   Author: swift-lang   File: HangChecker.java    License: Apache License 2.0 6 votes vote down vote up
private void dumpJVMThreads(PrintStream pw) {
    ThreadMXBean b = ManagementFactory.getThreadMXBean();
    if (b != null) {
        long[] ids = b.getAllThreadIds();
        if (ids != null && ids.length != 0) {
            ThreadInfo[] tis = b.getThreadInfo(ids, true, true); 
            pw.println("\nWaiting JVM threads:");
            for (ThreadInfo ti : tis) {
                Thread.State state = ti.getThreadState();
                if (state != Thread.State.RUNNABLE && state != Thread.State.TERMINATED) {
                    printThreadInfo(pw, ti);
                }
            }
        }
    }
}
 
Example #9
Source Project: dragonwell8_jdk   Author: alibaba   File: ConnectorStopDeadlockTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example #10
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JvmThreadInstanceEntryImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #11
Source Project: dragonwell8_jdk   Author: alibaba   File: TestThread.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Waits until {@link TestThread} is in the certain {@link State}
 * and blocking on {@code object}.
 *
 * @param state The thread state
 * @param object The object to block on
 */
public void waitUntilBlockingOnObject(Thread.State state, Object object) {
    String want = object == null ? null : object.getClass().getName() + '@'
            + Integer.toHexString(System.identityHashCode(object));
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.getThreadState() == state
                && (want == null || want.equals(ti.getLockName()))) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example #12
Source Project: visualvm   Author: oracle   File: JmxSupport.java    License: GNU General Public License v2.0 6 votes vote down vote up
synchronized boolean isReadOnlyConnection() {
    synchronized (readOnlyConnectionLock) {
        if (readOnlyConnection == null) {
            readOnlyConnection = Boolean.FALSE;
            ThreadMXBean threads = getThreadBean();
            if (threads != null) {
                try {
                    threads.getThreadInfo(1);
                } catch (SecurityException ex) {
                    readOnlyConnection = Boolean.TRUE;
                }
            }
        }
        return readOnlyConnection.booleanValue();
    }
}
 
Example #13
Source Project: openjdk-8   Author: bpupadhyaya   File: TestThread.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Waits until {@link TestThread} is in the certain {@link State}
 * and blocking on {@code object}.
 *
 * @param state The thread state
 * @param object The object to block on
 */
public void waitUntilBlockingOnObject(Thread.State state, Object object) {
    String want = object == null ? null : object.getClass().getName() + '@'
            + Integer.toHexString(System.identityHashCode(object));
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.getThreadState() == state
                && (want == null || want.equals(ti.getLockName()))) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example #14
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: JvmThreadingImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Getter for the "JvmThreadContentionMonitoring" variable.
 */
public EnumJvmThreadContentionMonitoring getJvmThreadContentionMonitoring()
    throws SnmpStatusException {

    ThreadMXBean mbean = getThreadMXBean();

    if(!mbean.isThreadContentionMonitoringSupported()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Unsupported ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringUnsupported;
    }

    if(mbean.isThreadContentionMonitoringEnabled()) {
        log.debug("getJvmThreadContentionMonitoring",
                  "Enabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringEnabled;
    } else {
        log.debug("getJvmThreadContentionMonitoring",
                  "Disabled ThreadContentionMonitoring");
        return JvmThreadContentionMonitoringDisabled;
    }
}
 
Example #15
Source Project: TencentKona-8   Author: Tencent   File: GetInternalThreads.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    long value = mbean.getInternalThreadCount();

    if (value < MIN_VALUE_FOR_PASS || value > MAX_VALUE_FOR_PASS) {
        throw new RuntimeException("Internal thread count " +
                                   "illegal value: " + value + " " +
                                   "(MIN = " + MIN_VALUE_FOR_PASS + "; " +
                                   "MAX = " + MAX_VALUE_FOR_PASS + ")");
    }

    System.out.println("Internal Thread Count = " + value);

    ThreadMXBean thread =
        ManagementFactory.getThreadMXBean();
    if (!thread.isThreadCpuTimeSupported()) {
        System.out.println("Thread Cpu Time is not supported.");
        return;
    }

    while(!testCPUTime()) {
        Thread.sleep(100);
    }
}
 
Example #16
Source Project: jmonitor   Author: coderczp   File: JMServer.java    License: GNU General Public License v2.0 6 votes vote down vote up
@HttpMapping(url = "/deadlockCheck")
public JSONObject doDeadlockCheck(Map<String, Object> param) {
    try {
        String app = ((HttpServletRequest) param.get(JMDispatcher.REQ)).getParameter("app");
        ThreadMXBean tBean = JMConnManager.getThreadMBean(app);
        JSONObject json = new JSONObject();
        long[] dTh = tBean.findDeadlockedThreads();
        if (dTh != null) {
            ThreadInfo[] threadInfo = tBean.getThreadInfo(dTh, Integer.MAX_VALUE);
            StringBuffer sb = new StringBuffer();
            for (ThreadInfo info : threadInfo) {
                sb.append("\n").append(info);
            }
            json.put("hasdeadlock", true);
            json.put("info", sb);
            return json;
        }
        json.put("hasdeadlock", false);
        return json;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #17
Source Project: banyan   Author: krisjin   File: ManagementFactoryTest.java    License: MIT License 6 votes vote down vote up
public static void main(String[] args) {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    List<GarbageCollectorMXBean> garbageCollectorMXBeanList = ManagementFactory.getGarbageCollectorMXBeans();

    for (GarbageCollectorMXBean gcMXBean : garbageCollectorMXBeanList) {
        String gcName = gcMXBean.getName();
        String memoryPoolNames[] = gcMXBean.getMemoryPoolNames();
        for (String memoryPoolName : memoryPoolNames) {
            System.out.println(memoryPoolName);
        }
        ObjectName objectName = gcMXBean.getObjectName();
        String domainName = objectName.getDomain();
        System.out.println(domainName+"__"+objectName.getCanonicalName());
        System.out.println(gcName);

    }

    //不需要获取同步的monitor 和 synchronize信息,仅获取线程和线程堆栈信息。
    ThreadInfo[] allThreads = threadMXBean.dumpAllThreads(true, true);
    for (ThreadInfo threadInfo : allThreads) {
        String threadName = threadInfo.getThreadName();
        long threadId = threadInfo.getThreadId();
        System.out.println(threadName + "," + threadId + "," + threadInfo.getLockOwnerName());
    }
}
 
Example #18
Source Project: brooklyn-server   Author: apache   File: AutoScalerPolicyTest.java    License: Apache License 2.0 6 votes vote down vote up
public static void dumpThreadsEtc() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] threads = threadMXBean.dumpAllThreads(true, true);
    for (ThreadInfo thread : threads) {
        System.out.println(thread.getThreadName()+" ("+thread.getThreadState()+")");
        for (StackTraceElement stackTraceElement : thread.getStackTrace()) {
            System.out.println("\t"+stackTraceElement);
        }
    }
    
    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
    MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
    System.out.println("Memory:");
    System.out.println("\tHeap: used="+heapMemoryUsage.getUsed()+"; max="+heapMemoryUsage.getMax()+"; init="+heapMemoryUsage.getInit()+"; committed="+heapMemoryUsage.getCommitted());
    System.out.println("\tNon-heap: used="+nonHeapMemoryUsage.getUsed()+"; max="+nonHeapMemoryUsage.getMax()+"; init="+nonHeapMemoryUsage.getInit()+"; committed="+nonHeapMemoryUsage.getCommitted());

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    System.out.println("OS:");
    System.out.println("\tsysLoadAvg="+operatingSystemMXBean.getSystemLoadAverage()+"; availableProcessors="+operatingSystemMXBean.getAvailableProcessors()+"; arch="+operatingSystemMXBean.getArch());
}
 
Example #19
Source Project: openjdk-8   Author: bpupadhyaya   File: JvmThreadInstanceEntryImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example #20
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

    validator.validate(operation);
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    try {
        long id = operation.require(PlatformMBeanConstants.ID).asLong();
        ThreadInfo info;
        if (operation.hasDefined(PlatformMBeanConstants.MAX_DEPTH)) {
            info = mbean.getThreadInfo(id, operation.require(PlatformMBeanConstants.MAX_DEPTH).asInt());
        } else {
            info = mbean.getThreadInfo(id);
        }

        final ModelNode result = context.getResult();
        if (info != null) {
            result.set(PlatformMBeanUtil.getDetypedThreadInfo(info, mbean.isThreadCpuTimeSupported()));
        }
    } catch (SecurityException e) {
        throw new OperationFailedException(e.toString());
    }
}
 
Example #21
Source Project: ehcache3   Author: ehcache   File: BasicClusteredWriteBehindTest.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
  if (doThreadDump) {
    System.out.println("Performing thread dump");
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true);
    Arrays.stream(threadInfos).forEach(System.out::println);
  }

  if (cacheManager != null) {
    cacheManager.close();
    cacheManager.destroy();
  }
}
 
Example #22
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JvmThreadingImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Getter for the "JvmThreadCpuTimeMonitoring" variable.
 */
public EnumJvmThreadCpuTimeMonitoring getJvmThreadCpuTimeMonitoring()
    throws SnmpStatusException {

    ThreadMXBean mbean = getThreadMXBean();

    if(!mbean.isThreadCpuTimeSupported()) {
        log.debug("getJvmThreadCpuTimeMonitoring",
                  "Unsupported ThreadCpuTimeMonitoring");
        return JvmThreadCpuTimeMonitoringUnsupported;
    }

    try {
        if(mbean.isThreadCpuTimeEnabled()) {
            log.debug("getJvmThreadCpuTimeMonitoring",
                  "Enabled ThreadCpuTimeMonitoring");
            return JvmThreadCpuTimeMonitoringEnabled;
        } else {
            log.debug("getJvmThreadCpuTimeMonitoring",
                      "Disabled ThreadCpuTimeMonitoring");
            return JvmThreadCpuTimeMonitoringDisabled;
        }
    }catch(UnsupportedOperationException e) {
        log.debug("getJvmThreadCpuTimeMonitoring",
                  "Newly unsupported ThreadCpuTimeMonitoring");

        return JvmThreadCpuTimeMonitoringUnsupported;
    }
}
 
Example #23
Source Project: uavstack   Author: uavorg   File: JVMToolHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static Map<String, Long> readThreadUsage(ThreadMXBean tmb) {

        Map<String, Long> m = new LinkedHashMap<String, Long>();

        m.put("thread_live", new Long(tmb.getThreadCount()));
        m.put("thread_daemon", new Long(tmb.getDaemonThreadCount()));
        m.put("thread_peak", new Long(tmb.getPeakThreadCount()));
        m.put("thread_started", tmb.getTotalStartedThreadCount());

        return m;
    }
 
Example #24
Source Project: webdsl   Author: webdsl   File: ThreadManager.java    License: Apache License 2.0 5 votes vote down vote up
static Thread[] getAllThreads( ) {
    final ThreadGroup root = getRootThreadGroup( );
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean( );
    int nAlloc = thbean.getThreadCount( );
    int n = 0;
    Thread[] threads;
    do {
        nAlloc *= 2;
        threads = new Thread[ nAlloc ];
        n = root.enumerate( threads, true );
    } while ( n == nAlloc );
    return java.util.Arrays.copyOf( threads, n );
}
 
Example #25
Source Project: Wikidata-Toolkit   Author: Wikidata   File: TimerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void enableCpuTimeTaking() {
	ThreadMXBean tmxb = ManagementFactory.getThreadMXBean();
	tmxb.setThreadCpuTimeEnabled(false);

	Timer timer = new Timer("Test timer", Timer.RECORD_ALL);
	timer.start();
	doDummyComputation();
	timer.stop();

	assertTrue("Timer should have measured a CPU time.",
			timer.getTotalCpuTime() > 0);
}
 
Example #26
Source Project: presto   Author: prestosql   File: ThreadResource.java    License: Apache License 2.0 5 votes vote down vote up
@ResourceSecurity(MANAGEMENT_READ)
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Info> getThreadInfo()
{
    ThreadMXBean mbean = ManagementFactory.getThreadMXBean();

    List<Info> threads = Arrays.stream(mbean.getThreadInfo(mbean.getAllThreadIds(), Integer.MAX_VALUE))
            .filter(Objects::nonNull)
            .map(ThreadResource::toInfo)
            .collect(Collectors.toUnmodifiableList());

    return Ordering.from(byName()).sortedCopy(threads);
}
 
Example #27
Source Project: Deta_Cache   Author: yaoguangluo   File: OperatingSystemInfoUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
	 * Java ��������߳�ϵͳ
	 */
	public static Map<String, String> showThread(){
		Map<String, String> map = new HashMap<>();
		ThreadMXBean thread = ManagementFactory.getThreadMXBean();
		//......���������ܶ���Ϣ
		map.put("ThreadCount", "" + thread.getThreadCount());
		map.put("AllThreadIds:", "" +  thread.getAllThreadIds());
		map.put("CurrentThreadUserTime", "" + thread.getCurrentThreadUserTime());
		return map;
//		System.out.println("ThreadCount" + thread.getThreadCount());
//		System.out.println("AllThreadIds:" + thread.getAllThreadIds());
//		System.out.println("CurrentThreadUserTime" + thread.getCurrentThreadUserTime());
	}
 
Example #28
Source Project: RoaringBitmap   Author: RoaringBitmap   File: TestIteratorMemory.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean isThreadAllocatedMemorySupported(ThreadMXBean threadMbean) {
  if (threadMbean != null && Stream.of(threadMbean.getClass().getInterfaces())
      .anyMatch(c -> c.getName().equals("com.sun.management.ThreadMXBean"))) {
    try {
      return (Boolean) Class.forName("com.sun.management.ThreadMXBean")
          .getMethod("isThreadAllocatedMemorySupported").invoke(threadMbean);
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
        | NoSuchMethodException | SecurityException | ClassNotFoundException e) {
      return false;
    }
  } else {
    return false;
  }
}
 
Example #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JvmThreadingImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Setter for the "JvmThreadContentionMonitoring" variable.
 */
public void setJvmThreadContentionMonitoring(
                        EnumJvmThreadContentionMonitoring x)
    throws SnmpStatusException {
    ThreadMXBean mbean = getThreadMXBean();

    // We can trust the received value, it has been checked in
    // checkJvmThreadContentionMonitoring
    if(JvmThreadContentionMonitoringEnabled.intValue() == x.intValue())
        mbean.setThreadContentionMonitoringEnabled(true);
    else
        mbean.setThreadContentionMonitoringEnabled(false);
}
 
Example #30
Source Project: visualvm   Author: oracle   File: ApplicationThreadsViewProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
static ThreadMXBean resolveThreads(Application application) {
    JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
    if (jmxModel != null && jmxModel.getConnectionState() == JmxModel.ConnectionState.CONNECTED) {
        if (jmxModel.isTakeThreadDumpSupported()) {
            JvmMXBeans mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
            return mxbeans == null ? null : mxbeans.getThreadMXBean();
        }
    }
    return null;
}