Package java.lang.management

Examples of java.lang.management.ThreadInfo


    private int countZkThreads() {
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] threadIds = threadBean.getAllThreadIds();
        int count = 0;
        for (long tid: threadIds) {
            ThreadInfo info = threadBean.getThreadInfo(tid);
            if (info == null) {
                continue;
            }
            String name = info.getThreadName();

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


    private void printAllZkThreads() {
        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)) {
                System.out.println(name);
            }
        }
View Full Code Here

            throw new RuntimeException("TEST FAILED.");
        System.out.println("Test passed.");
    }

    private static void checkSuspendedThreadState(Thread t, Thread.State state) {
        ThreadInfo info = tm.getThreadInfo(t.getId());
        if (info == null) {
            throw new RuntimeException(t.getName() +
               " expected to have ThreadInfo " +
               " but got null.");
        }

        if (info.getThreadState() != state) {
            throw new RuntimeException(t.getName() + " expected to be in " +
                state + " state but got " + info.getThreadState());
        }

        if (!info.isSuspended()) {
            throw new RuntimeException(t.getName() + " expected to be suspended " +
                " but isSuspended() returns " + info.isSuspended());
        }
        checkThreadState(t, state);
    }
View Full Code Here

        }
        checkThreadState(t, state);
    }

    private static void checkThreadState(Thread t, Thread.State expected) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        Thread.State state = ti.getThreadState();
        if (state == null) {
            throw new RuntimeException(t.getName() + " expected to have " +
                expected + " but got null.");
        }

        if (state != expected) {
            if (expected ==  Thread.State.BLOCKED) {
                int retryCount=0;
                while (ti.getThreadState() != expected) {
                    if (retryCount >= 500) {
                        throw new RuntimeException(t.getName() +
                            " expected to have " + expected + " but got " + state);
                     }
                     goSleep(100);
View Full Code Here

        return lock.getClass().getName() + '@' +
            Integer.toHexString(System.identityHashCode(lock));
    }

    private static void checkLockInfo(Thread t, Thread.State state, Object lock, Thread owner) {
        ThreadInfo info = tm.getThreadInfo(t.getId());
        if (info == null) {
            throw new RuntimeException(t.getName() +
               " expected to have ThreadInfo " +
               " but got null.");
        }

        if (info.getThreadState() != state) {
            throw new RuntimeException(t.getName() + " expected to be in " +
                state + " state but got " + info.getThreadState());
        }

        if (lock == null && info.getLockName() != null) {
            throw new RuntimeException(t.getName() +
                " expected not to be blocked on any lock" +
                " but got " + info.getLockName());
        }
        String expectedLockName = getLockName(lock);
        if (lock != null && info.getLockName() == null) {
            throw new RuntimeException(t.getName() +
                " expected to be blocked on lock [" + expectedLockName +
                "] but got null.");
        }

        if (lock != null && !expectedLockName.equals(info.getLockName())) {
            throw new RuntimeException(t.getName() +
                " expected to be blocked on lock [" + expectedLockName +
                "] but got [" + info.getLockName() + "].");
        }

        if (owner == null && info.getLockOwnerName() != null) {
            throw new RuntimeException("Lock owner is expected " +
                " to be null but got " + info.getLockOwnerName());
        }

        if (owner != null && info.getLockOwnerName() == null) {
            throw new RuntimeException("Lock owner is expected to be " +
                owner.getName() +
                " but got null.");
        }
        if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
            throw new RuntimeException("Lock owner is expected to be " +
                owner.getName() +
                " but got " + owner.getName());
        }
        if (owner == null && info.getLockOwnerId() != -1) {
            throw new RuntimeException("Lock owner is expected " +
                " to be -1 but got " + info.getLockOwnerId());
        }

        if (owner != null && info.getLockOwnerId() <= 0) {
            throw new RuntimeException("Lock owner is expected to be " +
                owner.getName() + "(id = " + owner.getId() +
                ") but got " + info.getLockOwnerId());
        }
        if (owner != null && info.getLockOwnerId() != owner.getId()) {
            throw new RuntimeException("Lock owner is expected to be " +
                owner.getName() + "(id = " + owner.getId() +
                ") but got " + info.getLockOwnerId());
        }
        if (info.isSuspended()) {
            throw new RuntimeException(t.getName() +
                " isSuspended() returns " + info.isSuspended());
        }
    }
View Full Code Here

                              validItemTypes);
        CompositeData cd =
            new CompositeDataSupport(ct,
                                     validItemNames,
                                     values);
        ThreadInfo info = ThreadInfo.from(cd);
        checkThreadInfo(info);
   }
View Full Code Here

                              v5ItemTypes);
        CompositeData cd =
            new CompositeDataSupport(ct,
                                     v5ItemNames,
                                     v5ItemValues);
        ThreadInfo info = ThreadInfo.from(cd);
        checkThreadInfo(info);
   }
View Full Code Here

            new CompositeDataSupport(ct,
                                     badItemNames,
                                     values);

        try {
            ThreadInfo info = ThreadInfo.from(cd);
        } catch (IllegalArgumentException e) {
            System.out.println("Expected exception: " +
                e.getMessage());
            return;
        }
View Full Code Here

            new CompositeDataSupport(ct,
                                     validItemNames,
                                     values);

        try {
            ThreadInfo info = ThreadInfo.from(cd);
        } catch (IllegalArgumentException e) {
            System.out.println("Expected exception: " +
                e.getMessage());
            return;
        }
View Full Code Here

            }
            stackTrace = newStackTrace;
        }

        // Ask our native to instantiate a ThreadInfo for us
        ThreadInfo ti = createThreadInfoImpl(threadId, threadName, threadState,
                isSuspendedImpl(thread), isInNative,
                getThreadBlockedCountImpl(thread), blockedTime,
                getThreadWaitedCountImpl(thread), waitedTime, lockName,
                lockOwnerId, lockOwnerName, stackTrace);
        return ti;
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.