List of usage examples for java.lang Thread getAllStackTraces
public static Map<Thread, StackTraceElement[]> getAllStackTraces()
From source file:com.kotcrab.vis.editor.util.vis.CrashReporter.java
private void printThreadInfo() { println("--- Threads ---"); Set<Thread> threadSet = Thread.getAllStackTraces().keySet(); for (Thread t : threadSet) { println("Thread: " + t.getName() + ", daemon: " + t.isDaemon() + ", state: " + t.getState()); for (StackTraceElement e : t.getStackTrace()) { crashReport.append("\t"); println(e.toString());//from ww w. j av a 2s.c om } println(); } println("---------------"); println(); }
From source file:org.apache.hadoop.hdfs.TestHttpServerShutdown.java
@Test(timeout = 180000) public void testShutdown() throws Exception { oldThreads = Thread.getAllStackTraces().keySet(); conf = new Configuration(); conf.setInt(HttpServer.HTTP_THREADPOOL_MAX_STOP_TIME, 3000); cluster = new MiniDFSCluster(conf, 0, true, null); InjectionHandler.set(new TestHandler()); Thread fsck = new FsckThread(); fsck.setDaemon(true);//from ww w .j av a 2 s. c om fsck.start(); while (!fsckCalled) { Thread.sleep(1000); LOG.info("Waiting for fsck to hit NN"); } cluster.shutdown(); LOG.info("Alive Non Daemon threads : "); for (Map.Entry<Thread, StackTraceElement[]> entry : Thread.getAllStackTraces().entrySet()) { Thread t = entry.getKey(); if (!t.isDaemon() && !oldThreads.contains(t)) { LOG.info("Thread : " + t.getName()); for (StackTraceElement e : entry.getValue()) { LOG.info(e); } fail("Thread : " + t.getName() + " is not a daemon thread"); } } }
From source file:org.apache.hadoop.hdfs.TestAvatarCleanShutdown.java
public void setUp(String name) throws Exception { LOG.info("------------------- test: " + name + ", federation: " + federation + " START ----------------"); oldThreads = new HashSet<Thread>(Thread.getAllStackTraces().keySet()); conf = new Configuration(); hosts = HOST_FILE_PATH + "_" + System.currentTimeMillis(); File f = new File(hosts); f.delete();//from w ww .j a va 2 s.co m f.createNewFile(); conf.set(FSConstants.DFS_HOSTS, hosts); conf.setInt("dfs.datanode.failed.volumes.tolerated", 0); if (!federation) { cluster = new MiniAvatarCluster.Builder(conf).build(); } else { cluster = new MiniAvatarCluster.Builder(conf).numNameNodes(2).federation(true).build(); } federation = false; }
From source file:com.twosigma.beaker.core.rest.UtilRest.java
@GET @Path("allStackTraces") public List<Map<String, Object>> getAllStackTraces() { List<Map<String, Object>> out = new ArrayList<>(); Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces(); for (Thread t : allStackTraces.keySet()) { Map<String, Object> map = new HashMap<>(); map.put("thread", t); map.put("stackTraces", allStackTraces.get(t)); out.add(map);/*w ww . j a v a 2 s .c om*/ } return out; }
From source file:com.l2jfree.gameserver.threadmanager.DeadlockDetector.java
private Thread findThreadById(long id) { for (Thread thread : Thread.getAllStackTraces().keySet()) if (thread.getId() == id) return thread; throw new IllegalStateException("Deadlocked Thread not found!"); }
From source file:com.cisco.oss.foundation.monitoring.service.TestMultiService.java
@Test public void testManyServices() throws Exception { MonitoringAgentFactory.getInstance().register( new PropertiesConfiguration(TestMultiService.class.getResource("/config.properties").getPath())); ExecutorService threadPool = Executors.newFixedThreadPool(10); int numOfServices = 1234; final CountDownLatch latch = new CountDownLatch(numOfServices); final ServiceDetails serviceDetails = new ServiceDetails("default desc", "test", "junit", 12345); for (int i = 0; i < numOfServices; i++) { final int index = i; threadPool.execute(new Runnable() { @Override/*from w w w .java 2s .c o m*/ public void run() { String apiName = (index % 3) + ""; CommunicationInfo.getCommunicationInfo().transactionStarted(serviceDetails, apiName, 125); try { Thread.sleep(2); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, apiName, (index % 2 == 0) ? false : true, "kuku"); latch.countDown(); } }); } try { latch.await(); } catch (InterruptedException e) { e.printStackTrace(); } int numberOfThreads = Thread.getAllStackTraces().keySet().size(); Assert.assertTrue(numberOfThreads <= 30); try { Thread.sleep(1500); } catch (InterruptedException e) { e.printStackTrace(); } Collection<Service> services = ServiceInfo.INSTANCE.getServices(); System.out.println("services: " + services.size()); for (Service service : services) { System.out.println("service: " + service + ". total: " + service.getTotalRequestCount()); } Assert.assertEquals(3, services.size()); // try { // Thread.sleep(60000); // } catch (InterruptedException e) { // e.printStackTrace(); // } }
From source file:com.streamsets.datacollector.main.TestLogConfigurator.java
@Test public void testClasspathLog4jConfig() { RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class); File configDir = new File("target", UUID.randomUUID().toString()); Assert.assertTrue(configDir.mkdirs()); Mockito.when(runtimeInfo.getConfigDir()).thenReturn(configDir.getAbsolutePath()); Mockito.when(runtimeInfo.getLog4jPropertiesFileName()).thenReturn("log4j.properties"); new LogConfigurator(runtimeInfo).configure(); Mockito.verify(runtimeInfo, Mockito.times(1)).getConfigDir(); for (Thread thread : Thread.getAllStackTraces().keySet()) { Assert.assertFalse(thread instanceof FileWatchdog); }// w w w.ja va 2s .c o m Mockito.verify(runtimeInfo, Mockito.times(1)) .setAttribute(Mockito.eq(RuntimeInfo.LOG4J_CONFIGURATION_URL_ATTR), Mockito.any()); }
From source file:com.github.xwgou.namesurfer.fxui.JFXNameSurfer.java
@Override public void stop() { logger.debug(Thread.getAllStackTraces().keySet().toString()); Platform.exit(); System.exit(0); }
From source file:ru.catssoftware.lang.L2Thread.java
public static List<String> getStats() { List<String> list = new FastList<String>(); list.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date())); list.add(""); list.add("## Java Platform Information ##"); list.add("Java Runtime Name: " + System.getProperty("java.runtime.name")); list.add("Java Version: " + System.getProperty("java.version")); list.add("Java Class Version: " + System.getProperty("java.class.version")); list.add(""); list.add("## Virtual Machine Information ##"); list.add("VM Name: " + System.getProperty("java.vm.name")); list.add("VM Version: " + System.getProperty("java.vm.version")); list.add("VM Vendor: " + System.getProperty("java.vm.vendor")); list.add("VM Info: " + System.getProperty("java.vm.info")); list.add(""); list.add("## OS Information ##"); list.add("Name: " + System.getProperty("os.name")); list.add("Architeture: " + System.getProperty("os.arch")); list.add("Version: " + System.getProperty("os.version")); list.add(""); list.add("## Runtime Information ##"); list.add("CPU Count: " + Runtime.getRuntime().availableProcessors()); list.add(""); for (String line : getMemoryUsageStatistics()) list.add(line);/*from w ww . j av a 2s.c o m*/ list.add(""); list.add("## Class Path Information ##\n"); for (String lib : System.getProperty("java.class.path").split(File.pathSeparator)) if (!list.contains(lib)) list.add(lib); list.add(""); Set<Thread> threads = Thread.getAllStackTraces().keySet(); list.add("## " + threads.size() + " thread(s) ##"); list.add("================================================="); int i = 1; for (Thread thread : threads) { list.add(""); list.add(i++ + "."); list.addAll(getStats(thread)); } return list; }
From source file:org.infoglue.deliver.util.CacheController.java
private static void printThreads() { ThreadGroup tg = Thread.currentThread().getThreadGroup(); int n = tg.activeCount(); logger.warn("Number of active threads: " + n); Thread[] threadArray = new Thread[n]; n = tg.enumerate(threadArray, false); for (int i = 0; i < n; i++) { String currentThreadId = "" + threadArray[i].getId(); Thread t = threadArray[i]; Map stacks = t.getAllStackTraces(); Iterator stacksIterator = stacks.values().iterator(); while (stacksIterator.hasNext()) { StackTraceElement[] el = (StackTraceElement[]) stacksIterator.next(); String stackString = ""; if (el != null && el.length != 0) { for (int j = 0; j < el.length; j++) { StackTraceElement frame = el[j]; if (frame == null) stackString += " null stack frame" + "<br/>"; else stackString += " null stack frame" + frame.toString() + "<br/>"; }//from w w w . jav a 2 s . c o m logger.warn("\n\nThreads:\n\n " + stackString); } } } }