List of usage examples for java.lang Thread getId
public long getId()
From source file:Main.java
/** * Print a stack trace of the current thread. *///from www . ja v a 2 s . c o m public static void printFullStackTrace() { Thread thread = Thread.currentThread(); System.out.printf(" Thread id: %d, name: %s, state: %s, daemon: %s, EDT: %s\n", thread.getId(), thread.getName(), thread.getState(), thread.isDaemon(), EventQueue.isDispatchThread()); ThreadGroup group = thread.getThreadGroup(); System.out.printf(" priority: %d, group: %s, group count: %d\n", thread.getPriority(), group.getName(), group.activeCount()); StackTraceElement[] backtrace = thread.getStackTrace(); for (StackTraceElement e : backtrace) { System.out.printf(" Stack Trace: %s\n", e); } }
From source file:Main.java
/** * Print diagnostic info about the current thread. */// w w w .j a va 2 s .c o m public static void printThreadInfo() { Thread thread = Thread.currentThread(); System.out.printf(" Thread id: %d, name: %s, state: %s, daemon: %s, EDT: %s\n", thread.getId(), thread.getName(), thread.getState(), thread.isDaemon(), EventQueue.isDispatchThread()); ThreadGroup group = thread.getThreadGroup(); System.out.printf(" priority: %d, group: %s, group count: %d\n", thread.getPriority(), group.getName(), group.activeCount()); StackTraceElement[] backtrace = thread.getStackTrace(); if (backtrace.length > 2) { System.out.printf(" trace[2]: %s\n", backtrace[2]); } }
From source file:com.clustercontrol.commons.util.MonitoredThreadPoolExecutor.java
public static void finishTask(Thread t) { // ???//from w ww .j a v a2 s . c o m ThreadInfo threadInfo = runningTaskMap.remove(t.getId()); if (log.isDebugEnabled()) { log.debug("finishing new monitored task : " + threadInfo); } }
From source file:de.micromata.genome.chronos.spi.HostUtils.java
/** * Gets the run context.//from w w w. j ava 2 s . c o m * * @param thread the thread * @return the run context */ public static String getRunContext(Thread thread) { String tid = "-1"; if (thread != null) { tid = Long.toHexString(thread.getId()); } String time = Long.toHexString(START_TIME / 1000); String t = time + ';' + tid; return t; }
From source file:Main.java
/** * Get the thread with the given ID. A null is returned * if no such thread is found./* w w w . j a va2 s .c o m*/ * * @param id the thread ID to search for * @return the thread, or null if not found */ public static Thread getThread(final long id) { final Thread[] threads = getAllThreads(); for (Thread thread : threads) if (thread.getId() == id) return thread; return null; }
From source file:Main.java
/** * Get the thread with the given ID and Name. A null is returned * if no such thread is found.// w w w. ja v a 2 s . co m * * @param id the thread ID to search for * @param name the thread name to search for * @return the thread, or null if not found */ public static Thread getThread(final long id, final String name) { final Thread[] threads = getAllThreads(); for (Thread thread : threads) if ((thread.getId() == id) && (thread.getName().equals(name))) return thread; return null; }
From source file:Main.java
/** * Get the thread with the given ID. A null is returned if no such thread is * found.// w ww . j a va 2 s .c om * * @param id * the thread ID to search for * @return the thread, or null if not found */ public static Thread getThread(final long id) { final Thread[] threads = getAllThreads(); for (Thread thread : threads) { if (thread.getId() == id) return thread; } return null; }
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. * * @param name the thread name to search for * @return the thread info, or null if not found * @throws NullPointerException/* ww w. ja v a 2s . c o m*/ * 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:Main.java
public static String gerThreadDump(Thread thread) { Preconditions.checkNotNull(thread);/*from ww w .j a v a 2 s . c o m*/ StringBuffer dump = new StringBuffer(200); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo threadInfo = threadMXBean.getThreadInfo(thread.getId(), 100); dump.append(lineSeperator); dump.append('"'); dump.append(threadInfo.getThreadName()); dump.append("\" "); final Thread.State state = threadInfo.getThreadState(); dump.append(lineSeperator); dump.append(" State: "); dump.append(state); final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace(); for (final StackTraceElement stackTraceElement : stackTraceElements) { dump.append(lineSeperator); dump.append(" at "); dump.append(stackTraceElement); } dump.append(lineSeperator); return dump.toString(); }
From source file:Main.java
/** * Get the thread info for the given thread. A null is * returned if the thread info cannot be found. * * @param thread the thread to search for * @return the thread info, or null if not found * @throws NullPointerException// www .ja v a 2s . c om * if thread is null */ public static ThreadInfo getThreadInfo(final Thread thread) { if (thread == null) throw new NullPointerException("Null thread"); return getThreadInfo(thread.getId()); }