List of usage examples for java.lang Thread getId
public long getId()
From source file:Main.java
/** * Get the thread info for the thread with the given name. A null is * returned if no such thread info is found. If more than one thread has the * same name, the thread info for the first one found is returned. * /* w w w . j a v a 2s. c o m*/ * @param name * the thread name to search for * @return the thread info, or null if not found * @throws NullPointerException * if the name is null */ public static ThreadInfo getThreadInfo(final String name) { if (name == null) { throw new NullPointerException("Null name"); } final Thread[] threads = getAllThreads(); for (Thread thread : threads) { if (thread.getName().equals(name)) { return getThreadInfo(thread.getId()); } } return null; }
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)) {/* ww w.jav a 2s . 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:Main.java
/** * Get the thread info for the given thread. A null is returned if the * thread info cannot be found.//from w w w. j a v a 2 s . c o m * * @param thread * the thread to search for * @return the thread info, or null if not found * @throws NullPointerException * if thread is null */ public static ThreadInfo getThreadInfo(final Thread thread) { if (thread == null) { throw new NullPointerException("Null thread"); } return getThreadInfo(thread.getId()); }
From source file:org.nuxeo.runtime.management.jvm.ThreadDeadlocksDetector.java
protected static Map<Long, Thread> getThreads() { ThreadGroup root = rootGroup(Thread.currentThread().getThreadGroup()); int nThreads = root.activeCount(); Thread[] threads = new Thread[2 * nThreads]; root.enumerate(threads);/*from ww w . ja v a 2 s .co m*/ Map<Long, Thread> map = new HashMap<Long, Thread>(threads.length); for (Thread thread : threads) { if (thread == null) { continue; } map.put(thread.getId(), thread); } return map; }
From source file:org.apache.bookkeeper.common.testing.util.TimedOutTestsListener.java
static String buildThreadDump() { StringBuilder dump = new StringBuilder(); Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> e : stackTraces.entrySet()) { Thread thread = e.getKey(); dump.append(String.format("\"%s\" %s prio=%d tid=%d %s\njava.lang.Thread.State: %s", thread.getName(), (thread.isDaemon() ? "daemon" : ""), thread.getPriority(), thread.getId(), Thread.State.WAITING.equals(thread.getState()) ? "in Object.wait()" : StringUtils.lowerCase(thread.getState().name()), Thread.State.WAITING.equals(thread.getState()) ? "WAITING (on object monitor)" : thread.getState())); for (StackTraceElement stackTraceElement : e.getValue()) { dump.append("\n at "); dump.append(stackTraceElement); }//from w w w . jav a 2 s .c o m dump.append("\n"); } return dump.toString(); }
From source file:com.clustercontrol.commons.util.MonitoredThreadPoolExecutor.java
public static void beginTask(Thread t, String className) { // ThreadLocal?? HinemosSessionContext.instance().setProperty(JpaTransactionManager.EM, null); // ??//w w w. j a v a2s .com ThreadInfo threadInfo = new ThreadInfo(t, className, HinemosTime.currentTimeMillis()); runningTaskMap.put(t.getId(), threadInfo); if (log.isDebugEnabled()) { log.debug("starting new monitored task : " + threadInfo); } }
From source file:kr.co.aim.nanoframe.nanoFrameServiceProxy.java
/** * bundleContext:bundle// w w w .jav a 2s .c om * @return */ public static BundleContext getBundleContext() { if (bundleContext == null) { Thread thread = Thread.currentThread(); log.info("GETBUNDLE : " + thread.getName()); threadMap.put(thread.getId(), thread); try { Thread.sleep(BundleUtil.getServiceLookupTimeout()); } catch (InterruptedException ex) { return bundleContext; } finally { threadMap.remove(thread.getId()); } throw new nanoFrameErrorSignal(ErrorSignal.NotActive, "nanoframe.kernel is not Active."); } else return bundleContext; }
From source file:majordodo.task.BrokerTestUtils.java
public static String getThreadName(long threadid) { for (Thread t : Thread.getAllStackTraces().keySet()) { if (t.getId() == threadid) { return t.getName(); }/*w w w. j a va2 s . co m*/ } return null; }
From source file:com.jkoolcloud.tnt4j.streams.outputs.AbstractJKCloudOutput.java
private static String getTrackersMapKey(Thread t, String sourceFQN) { return (t == null ? "null" : t.getId()) + ":?:" + sourceFQN; // NON-NLS }
From source file:org.midonet.midolman.Midolman.java
public static void dumpStacks() { Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces(); for (Thread thread : traces.keySet()) { System.err.print("\"" + thread.getName() + "\" "); if (thread.isDaemon()) System.err.print("daemon "); System.err.print(String.format("prio=%x tid=%x %s [%x]\n", thread.getPriority(), thread.getId(), thread.getState(), System.identityHashCode(thread))); StackTraceElement[] trace = traces.get(thread); for (StackTraceElement e : trace) { System.err.println(" at " + e.toString()); }//w w w . jav a2 s.co m } }