List of usage examples for java.lang Thread getAllStackTraces
public static Map<Thread, StackTraceElement[]> getAllStackTraces()
From source file:Main.java
public static void dumpAllThreadStacks() { System.out.println("stack trace"); Map<Thread, StackTraceElement[]> map = Thread.getAllStackTraces(); for (Thread t : map.keySet()) { StackTraceElement[] elements = map.get(t); System.out.println(t);/*w w w . j av a 2s.c o m*/ System.out.println("isDaemon : " + t.isDaemon() + ", isAlive : " + t.isAlive() + ", isInterrupted : " + t.isInterrupted()); for (StackTraceElement e : elements) { System.out.println("\t" + e); } System.out.println(""); } }
From source file:Main.java
/** * Print a string representation of the current stack state of all the active threads. *//*ww w . j a v a2 s . c om*/ public static void printStackTraces(PrintWriter writer) { Map<Thread, StackTraceElement[]> map; try { map = Thread.getAllStackTraces(); } catch (Throwable e) { writer.println("Failed to obtain stack traces: " + e); return; } if (map == null) { writer.println("No stack traces available"); return; } for (Entry<Thread, StackTraceElement[]> entry : map.entrySet()) printStackTrace(writer, entry.getKey(), entry.getValue()); writer.flush(); }
From source file:org.exfio.weave.client.WeaveClientCLI.java
public static List<Thread> getThreads() { Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); return Arrays.asList(threadSet.toArray(new Thread[threadSet.size()])); }
From source file:com.fotonauts.lackr.TestESI.java
@After public void tearDown() throws Exception { LifeCycle[] zombies = new LifeCycle[] { client, proxyServer, remoteControlledStub }; for (LifeCycle z : zombies) z.stop();/*from w w w . j a va2 s . co m*/ assertTrue(Thread.getAllStackTraces().size() < 10); }
From source file:com.streamsets.datacollector.main.TestLogConfigurator.java
@After public void cleanUp() throws Exception { System.getProperties().remove("log4j.configuration"); System.getProperties().remove("log4j.defaultInitOverride"); for (Thread thread : Thread.getAllStackTraces().keySet()) { if (thread instanceof FileWatchdog) { Field interrupted = ((Class) thread.getClass().getGenericSuperclass()) .getDeclaredField("interrupted"); interrupted.setAccessible(true); interrupted.set(thread, true); thread.interrupt();// w w w .j a v a2 s . c om } } }
From source file:org.paxle.gui.impl.servlets.TheaddumpView.java
@Override protected void fillContext(Context context, HttpServletRequest request) { try {/*from w w w. j a v a2 s . c o m*/ // get the current dump Map<Thread, StackTraceElement[]> dumps = Thread.getAllStackTraces(); context.put("dumps", dumps); } catch (Exception e) { this.logger.error("Error", e); } }
From source file:org.synchronoss.cloud.nio.multipart.example.utils.ContextFinalizer.java
@Override public void onApplicationEvent(ContextClosedEvent event) { if (log.isInfoEnabled()) log.info("onApplicationEvent: " + event); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver driver = null;//from ww w . j a v a 2s . c o m while (drivers.hasMoreElements()) { try { driver = drivers.nextElement(); DriverManager.deregisterDriver(driver); if (log.isWarnEnabled()) log.warn(String.format("Driver %s unregistered", driver)); } catch (SQLException e) { if (log.isWarnEnabled()) log.warn(String.format("Error unregistering driver %s", driver), e); } } Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread thread : threadArray) { if (thread.getName().contains("Abandoned connection cleanup thread")) { synchronized (thread) { thread.stop(); //don't complain, it works } } } if (log.isInfoEnabled()) log.info("Finished processing onApplicationEvent"); }
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 a2s. c o m dump.append("\n"); } return dump.toString(); }
From source file:org.davidmendoza.fileUpload.utils.ContextFinalizer.java
@Override public void onApplicationEvent(ContextClosedEvent e) { log.info("Stopping connections"); Enumeration<Driver> drivers = DriverManager.getDrivers(); Driver d = null;//from w ww . j av a2s . c om while (drivers.hasMoreElements()) { try { d = drivers.nextElement(); DriverManager.deregisterDriver(d); log.warn(String.format("Driver %s deregistered", d)); } catch (SQLException ex) { log.warn(String.format("Error deregistering driver %s", d), ex); } } Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); Thread[] threadArray = threadSet.toArray(new Thread[threadSet.size()]); for (Thread t : threadArray) { if (t.getName().contains("Abandoned connection cleanup thread")) { synchronized (t) { t.stop(); //don't complain, it works } } } log.info("Finished stopping connections"); }
From source file:com.kotcrab.vis.editor.util.CrashReporter.java
private void printThreadInfo() { println("--- Threads ---"); Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); for (Thread t : threadSet) { if (t.isDaemon()) { println("Skipping daemon thread: " + t.getName()); } else {/* w w w .j av a 2 s . co m*/ println("Thread: " + t.getName()); for (StackTraceElement e : t.getStackTrace()) { crashReport.append("\t"); println(e.toString()); } } println(); } println("---------------"); println(); }