当前位置: 首页>>代码示例>>Java>>正文


Java ThreadInfo.getLockOwnerId方法代码示例

本文整理汇总了Java中java.lang.management.ThreadInfo.getLockOwnerId方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadInfo.getLockOwnerId方法的具体用法?Java ThreadInfo.getLockOwnerId怎么用?Java ThreadInfo.getLockOwnerId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ThreadInfo的用法示例。


在下文中一共展示了ThreadInfo.getLockOwnerId方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private String getThreadInfo(ThreadInfo ti) {
	String message = "\"" + ti.getThreadName() + "\" [ID=" + ti.getThreadId() + "]";
	message += " is " + ti.getThreadState();
	
	if (ti.isSuspended()) {
		message += " (suspended)";
	}
	
	if (ti.isInNative()) {
		message += " (running in native)";
	}

	message += ":\n";
	
	if (ti.getLockName() != null) {
		message += INDENT + "waiting to lock " + ti.getLockName() + "\n";
	}
	
	if (ti.getLockOwnerName() != null) {
		message += INDENT + "owned by \"" + ti.getLockOwnerName() + "\" [ID=" + ti.getLockOwnerId() + "]\n";
	}
	
	return message;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:ThreadManager.java

示例2: waitForBlock

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
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();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ConnectorStopDeadlockTest.java

示例3: ThreadDump

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private ThreadDump(
        final Map<Thread, StackTraceElement[]> stackTraces,
        final Thread.State stateIn) {
    super();

    Thread thread;
    // collect single dumps
    for (final Map.Entry<Thread, StackTraceElement[]> entry: stackTraces.entrySet()) {
        thread = entry.getKey();
        final StackTraceElement[] stackTraceElements = entry.getValue();
        StackTraceElement ste;
        String tracename = "";
        final State threadState = thread.getState();
        final ThreadInfo info = Memory.threadBean.getThreadInfo(thread.getId());
        if (threadState != null && info != null && (stateIn == null || stateIn.equals(threadState)) && stackTraceElements.length > 0) {
            final StringBuilder sb = new StringBuilder(3000);
            final String threadtitle = tracename + "THREAD: " + thread.getName() + " " + (thread.isDaemon()?"daemon":"") + " id=" + thread.getId() + " " + threadState.toString() + (info.getLockOwnerId() >= 0 ? " lock owner =" + info.getLockOwnerId() : "");
            boolean cutcore = true;
            for (int i = 0; i < stackTraceElements.length; i++) {
                ste = stackTraceElements[i];
                String className = ste.getClassName();
                String classString = ste.toString();
                if (cutcore && (className.startsWith("java.") || className.startsWith("sun."))) {
                    sb.setLength(0);
                    bufferappend(sb, tracename + "at " + classString);
                } else {
                    cutcore = false;
                    bufferappend(sb, tracename + "at " + classString);
                }
            }
            final StackTrace stackTrace = new StackTrace(sb.toString());
            SortedSet<String> threads = get(stackTrace);
            if (threads == null) {
                threads = new TreeSet<String>();
                put(stackTrace, threads);
            }
            threads.add(threadtitle);
        }
    }
}
 
开发者ID:yacy,项目名称:yacy_grid_mcp,代码行数:41,代码来源:ThreaddumpService.java

示例4: dumpThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void dumpThread(ThreadInfo thread, Logger log, Level level)
{
    if (thread == null) return;
    if ( thread.getThreadState() != State.WAITING )
    {
        log.log( level, "------------------------------" );
        //
        log.log( level, "Current Thread: " + thread.getThreadName() );
        log.log( level, "\tPID: " + thread.getThreadId()
                + " | Suspended: " + thread.isSuspended()
                + " | Native: " + thread.isInNative()
                + " | State: " + thread.getThreadState() 
                + " | Blocked Time: " + thread.getBlockedTime()     // Cauldron add info about blocked time
                + " | Blocked Count: " + thread.getBlockedCount()); // Cauldron add info about blocked count
        
        if ( thread.getLockedMonitors().length != 0 )
        {
            log.log( level, "\tThread is waiting on monitor(s):" );
            for ( MonitorInfo monitor : thread.getLockedMonitors() )
            {
                log.log( level, "\t\tLocked on:" + monitor.getLockedStackFrame() );
            }
        }
        if ( thread.getLockOwnerId() != -1 ) log.log( level, "\tLock Owner Id: " + thread.getLockOwnerId()); // Cauldron + add info about lock owner thread id
        log.log( level, "\tStack:" );
        //
        StackTraceElement[] stack = thread.getStackTrace();
        for ( int line = 0; line < stack.length; line++ )
        {
            log.log( level, "\t\t" + stack[line].toString() );
        }
    }
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:34,代码来源:WatchdogThread.java

示例5: checkLockInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void checkLockInfo(ThreadStateController t, Thread.State state,
                                  Object lock, Thread owner) {
    ThreadInfo info = getThreadInfo(t, state);
    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());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:68,代码来源:ThreadMXBeanStateTest.java

示例6: checkThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:54,代码来源:ThreadInfoCompositeData.java

示例7: checkThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }
    if (!values[DAEMON].equals(info.isDaemon())) {
        throw new RuntimeException("Daemon = " +
           info.isDaemon() + " expected = " +
           values[DAEMON]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:59,代码来源:ThreadInfoCompositeData.java


注:本文中的java.lang.management.ThreadInfo.getLockOwnerId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。