Package java.lang.management

Examples of java.lang.management.ThreadInfo


        baseHeapMemoryConsumption = memoryBean.getHeapMemoryUsage().getUsed();

        targetThread.start();
        for (;;) {
            Thread.State state;
            ThreadInfo info = threadBean.getThreadInfo(targetThread.getId());
            if (info == null) {
                state = Thread.State.TERMINATED;
            } else {
                state = info.getThreadState();
            }
            if (state == Thread.State.RUNNABLE || state == Thread.State.NEW || state == Thread.State.TERMINATED) {
                updateConsumptions();
                try {
                    sendRunningMessage(timeConsumption, memoryConsumption);
View Full Code Here


                mb.setThreadContentionMonitoringEnabled(false);
                Thread.yield();
            }// end while

            // Check that a ThreadInfo returns -1 where expected.
            ThreadInfo info = mb.getThreadInfo(Thread.currentThread().getId());
            assertEquals(-1, info.getBlockedTime());
            assertEquals(-1, info.getWaitedTime());

            // re-enable tcm
            while (!mb.isThreadContentionMonitoringEnabled()) {
                mb.setThreadContentionMonitoringEnabled(true);
                Thread.yield();
            }// end while

            // Check that waited time and blocked time are now no longer
            // set to -1.
            ThreadInfo info2 = mb.getThreadInfo(Thread.currentThread().getId());
            assertTrue(info2.getBlockedTime() > -1);
            assertTrue(info2.getWaitedTime() > -1);
        } else {
            try {
                mb.isThreadContentionMonitoringEnabled();
                fail("Should have thrown UnsupportedOperationException!");
            } catch (UnsupportedOperationException ignore) {
View Full Code Here

                SimpleType.STRING };
        CompositeType compositeType = new CompositeType(ThreadInfo.class
                .getName(), ThreadInfo.class.getName(), names, names, types);
        CompositeData data = new CompositeDataSupport(compositeType, names,
                values);
        ThreadInfo threadInfo = ThreadInfo.from(data);
        assertEquals(values[0], threadInfo.getThreadId());
        assertEquals(values[1], threadInfo.getThreadName());
        assertEquals(GOOD_THREAD_STATE, threadInfo.getThreadState());
        assertEquals(values[3], threadInfo.isSuspended());
        assertEquals(values[4], threadInfo.isInNative());
        assertEquals(values[5], threadInfo.getBlockedCount());
        assertEquals(values[6], threadInfo.getBlockedTime());
        assertEquals(values[7], threadInfo.getWaitedCount());
        assertEquals(values[8], threadInfo.getWaitedTime());
        assertEquals(values[9], threadInfo.getLockName());
        assertEquals(values[10], threadInfo.getLockOwnerId());
        assertEquals(values[11], threadInfo.getLockOwnerName());
        StackTraceElement[] stackElements = threadInfo.getStackTrace();
        assertEquals(GOOD_STACK_SIZE, stackElements.length);
        for (StackTraceElement element : stackElements) {
            assertEquals(GOOD_STACK_CLASSNAME, element.getClassName());
            assertEquals(GOOD_STACK_NATIVEMETHOD, element.isNativeMethod());
            assertEquals(GOOD_STACK_FILENAME, element.getFileName());
View Full Code Here

                SimpleType.LONG, SimpleType.STRING, SimpleType.LONG,
                SimpleType.STRING, stackTraceArray, SimpleType.STRING };
        CompositeType compositeType = getCompositeType(initialNames, types);
        CompositeData data = new CompositeDataSupport(compositeType,
                initialNames, initialValues);
        ThreadInfo threadInfo = ThreadInfo.from(data);
        assertEquals(initialValues[0], threadInfo.getThreadId());
        assertEquals(initialValues[1], threadInfo.getThreadName());
        assertEquals(GOOD_THREAD_STATE, threadInfo.getThreadState());
        assertEquals(initialValues[3], threadInfo.isSuspended());
        assertEquals(initialValues[4], threadInfo.isInNative());
        assertEquals(initialValues[5], threadInfo.getBlockedCount());
        assertEquals(initialValues[6], threadInfo.getBlockedTime());
        assertEquals(initialValues[7], threadInfo.getWaitedCount());
        assertEquals(initialValues[8], threadInfo.getWaitedTime());
        assertEquals(initialValues[9], threadInfo.getLockName());
        assertEquals(initialValues[10], threadInfo.getLockOwnerId());
        assertEquals(initialValues[11], threadInfo.getLockOwnerName());
        StackTraceElement[] stackElements = threadInfo.getStackTrace();
        assertEquals(GOOD_STACK_SIZE, stackElements.length);
        for (StackTraceElement element : stackElements) {
            assertEquals(GOOD_STACK_CLASSNAME, element.getClassName());
            assertEquals(GOOD_STACK_NATIVEMETHOD, element.isNativeMethod());
            assertEquals(GOOD_STACK_FILENAME, element.getFileName());
View Full Code Here

                SimpleType.LONG, SimpleType.STRING, SimpleType.LONG,
                SimpleType.STRING, stackTraceArray, SimpleType.STRING };
        CompositeType compositeType = getCompositeType(initialNames, types);
        CompositeData data = new CompositeDataSupport(compositeType,
                initialNames, initialValues);
        ThreadInfo threadInfo = ThreadInfo.from(data);
        assertEquals(initialValues[0], threadInfo.getThreadId());
        assertEquals(initialValues[1], threadInfo.getThreadName());
        assertEquals(GOOD_THREAD_STATE, threadInfo.getThreadState());
        assertEquals(initialValues[3], threadInfo.isSuspended());
        assertEquals(initialValues[4], threadInfo.isInNative());
        assertEquals(initialValues[5], threadInfo.getBlockedCount());
        assertEquals(initialValues[6], threadInfo.getBlockedTime());
        assertEquals(initialValues[7], threadInfo.getWaitedCount());
        assertEquals(initialValues[8], threadInfo.getWaitedTime());
        assertNull(threadInfo.getLockName());
        assertEquals(initialValues[10], threadInfo.getLockOwnerId());
        assertEquals(initialValues[11], threadInfo.getLockOwnerName());
        StackTraceElement[] stackElements = threadInfo.getStackTrace();
        assertEquals(GOOD_STACK_SIZE, stackElements.length);
        for (StackTraceElement element : stackElements) {
            assertEquals(GOOD_STACK_CLASSNAME, element.getClassName());
            assertEquals(GOOD_STACK_NATIVEMETHOD, element.isNativeMethod());
            assertEquals(GOOD_STACK_FILENAME, element.getFileName());
View Full Code Here

                .isCurrentThreadCpuTimeSupported());
        assertEquals(mb.isThreadContentionMonitoringSupported(), proxy
                .isThreadContentionMonitoringSupported());
        assertEquals(mb.isThreadCpuTimeSupported(), proxy
                .isThreadCpuTimeSupported());
        ThreadInfo info1 = mb.getThreadInfo(Thread.currentThread().getId());
        ThreadInfo info2 = proxy.getThreadInfo(Thread.currentThread().getId());
        // RI does not appear to override equals() for ThreadInfo so we take
        // the scenic route to check for equality...
        assertEquals(info1.getThreadId(), info2.getThreadId());
        assertEquals(info1.getBlockedCount(), info2.getBlockedCount());
        assertEquals(info1.getBlockedTime(), info2.getBlockedTime());
        assertEquals(info1.getThreadName(), info2.getThreadName());
        assertEquals(info1.getWaitedCount(), info2.getWaitedCount());
        assertEquals(info1.getLockName(), info2.getLockName());
    }
View Full Code Here

        StringBuilder sb=new StringBuilder();
        ThreadMXBean bean=ManagementFactory.getThreadMXBean();
        long[] ids=bean.getAllThreadIds();
        ThreadInfo[] threads=bean.getThreadInfo(ids, 20);
        for(int i=0; i < threads.length; i++) {
            ThreadInfo info=threads[i];
            if(info == null)
                continue;
            sb.append(info.getThreadName()).append(":\n");
            StackTraceElement[] stack_trace=info.getStackTrace();
            for(int j=0; j < stack_trace.length; j++) {
                StackTraceElement el=stack_trace[j];
                sb.append("    at ").append(el.getClassName()).append(".").append(el.getMethodName());
                sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")");
                sb.append("\n");
View Full Code Here

        StringBuilder sb=new StringBuilder();
        ThreadMXBean bean=ManagementFactory.getThreadMXBean();
        long[] ids=bean.getAllThreadIds();
        ThreadInfo[] threads=bean.getThreadInfo(ids, 20);
        for(int i=0; i < threads.length; i++) {
            ThreadInfo info=threads[i];
            if(info == null)
                continue;
            sb.append(info.getThreadName()).append(":\n");
            StackTraceElement[] stack_trace=info.getStackTrace();
            for(int j=0; j < stack_trace.length; j++) {
                StackTraceElement el=stack_trace[j];
                sb.append("    at ").append(el.getClassName()).append(".").append(el.getMethodName());
                sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")");
                sb.append("\n");
View Full Code Here

    {
        if (i >= threads.length)
        {
            return "";
        }
        final ThreadInfo thread = threads[i];

        final StringBuilder trace = new StringBuilder();
        for (int stack_i = 0; stack_i < Math.min(thread.getStackTrace().length,MAX_STACK); stack_i++)
        {
            if (stack_i == (MAX_STACK - 1))
            {
                trace.append("    ...");
            }
            else
            {
                trace.append("    at ").append(thread.getStackTrace()[stack_i]).append("\n");
            }
        }

        return "\"" + thread.getThreadName() + "\", id " + thread.getThreadId() + " is " + thread.getThreadState() + " on " + thread.getLockName()
                + ", owned by " + thread.getLockOwnerName() + ", id " + thread.getLockOwnerId() + "\n" + trace + "\n\n" + stacktraces(threads,i + 1);
    }
View Full Code Here

    private String findZkThread() {
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] threadIds = threadBean.getAllThreadIds();
        for (long tid: threadIds) {
            ThreadInfo info = threadBean.getThreadInfo(tid);

            String name = info.getThreadName();

            if (name.contains(ZK_THREAD_MARKER)) {
                return name;
            }
        }
View Full Code Here

TOP

Related Classes of java.lang.management.ThreadInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.