List of usage examples for java.lang ThreadGroup activeCount
public int activeCount()
From source file:com.googlecode.psiprobe.controllers.threads.ListThreadsController.java
private List enumerateThreads(final Map classLoaderMap) { ///*from w ww. ja va2 s .com*/ // get top ThreadGroup // ThreadGroup masterGroup = Thread.currentThread().getThreadGroup(); while (masterGroup.getParent() != null) { masterGroup = masterGroup.getParent(); } // // enumerate all Threads starting from top // List threadList = new ArrayList(); Thread[] threads = new Thread[masterGroup.activeCount()]; int numThreads = masterGroup.enumerate(threads); for (int i = 0; i < numThreads; i++) { ThreadModel threadModel = new ThreadModel(); threadModel.setThreadClass(threads[i].getClass().getName()); threadModel.setName(threads[i].getName()); threadModel.setPriority(threads[i].getPriority()); threadModel.setDaemon(threads[i].isDaemon()); threadModel.setInterrupted(threads[i].isInterrupted()); if (threads[i].getThreadGroup() != null) { threadModel.setGroupName(threads[i].getThreadGroup().getName()); } Object target = Instruments.getField(threads[i], "target"); if (target != null) { threadModel.setRunnableClassName(target.getClass().getName()); } ClassLoader cl = threads[i].getContextClassLoader(); if (cl != null) { if (classLoaderMap != null) { threadModel.setAppName((String) classLoaderMap.get(toUID(cl))); } threadModel.setClassLoader(toUID(cl)); } threadList.add(threadModel); } return threadList; }
From source file:psiprobe.controllers.threads.ListThreadsController.java
/** * Enumerate threads.//from www . j a v a2s. com * * @param classLoaderMap the class loader map * @return the list */ private List<ThreadModel> enumerateThreads(final Map<String, String> classLoaderMap) { // get top ThreadGroup ThreadGroup masterGroup = Thread.currentThread().getThreadGroup(); while (masterGroup.getParent() != null) { masterGroup = masterGroup.getParent(); } // enumerate all Threads starting from top List<ThreadModel> threadList = new ArrayList<>(); Thread[] threads = new Thread[masterGroup.activeCount()]; int numThreads = masterGroup.enumerate(threads); for (int i = 0; i < numThreads; i++) { ThreadModel threadModel = new ThreadModel(); threadModel.setThreadClass(threads[i].getClass().getName()); threadModel.setName(threads[i].getName()); threadModel.setPriority(threads[i].getPriority()); threadModel.setDaemon(threads[i].isDaemon()); threadModel.setInterrupted(threads[i].isInterrupted()); if (threads[i].getThreadGroup() != null) { threadModel.setGroupName(threads[i].getThreadGroup().getName()); } Object target = Instruments.getField(threads[i], "target"); if (target != null) { threadModel.setRunnableClassName(target.getClass().getName()); } ClassLoader cl = threads[i].getContextClassLoader(); if (cl != null) { if (classLoaderMap != null) { threadModel.setAppName(classLoaderMap.get(toUid(cl))); } threadModel.setClassLoader(toUid(cl)); } threadList.add(threadModel); } return threadList; }
From source file:net.testdriven.psiprobe.controllers.threads.ListThreadsController.java
private List enumerateThreads(final Map classLoaderMap) { ////from w w w . j av a 2 s . c o m // get top ThreadGroup // ThreadGroup masterGroup = Thread.currentThread().getThreadGroup(); while (masterGroup.getParent() != null) { masterGroup = masterGroup.getParent(); } // // enumerate all Threads starting from top // List<ThreadModel> threadList = new ArrayList<>(); Thread[] threads = new Thread[masterGroup.activeCount()]; int numThreads = masterGroup.enumerate(threads); for (int i = 0; i < numThreads; i++) { ThreadModel threadModel = new ThreadModel(); threadModel.setThreadClass(threads[i].getClass().getName()); threadModel.setName(threads[i].getName()); threadModel.setPriority(threads[i].getPriority()); threadModel.setDaemon(threads[i].isDaemon()); threadModel.setInterrupted(threads[i].isInterrupted()); if (threads[i].getThreadGroup() != null) { threadModel.setGroupName(threads[i].getThreadGroup().getName()); } Object target = Instruments.getField(threads[i], "target"); if (target != null) { threadModel.setRunnableClassName(target.getClass().getName()); } ClassLoader cl = threads[i].getContextClassLoader(); if (cl != null) { if (classLoaderMap != null) { threadModel.setAppName((String) classLoaderMap.get(toUID(cl))); } threadModel.setClassLoader(toUID(cl)); } threadList.add(threadModel); } return threadList; }
From source file:com.adito.setup.forms.SystemInfoForm.java
private void dumpThread(ThreadGroup group, int level, StringBuffer buf) { for (int i = 0; i < level; i++) { buf.append(" "); }// w w w . java 2s . c o m buf.append("["); buf.append(group.getName()); buf.append("]"); Thread[] t = new Thread[group.activeCount()]; group.enumerate(t); for (int i = 0; t != null && i < t.length; i++) { if (t[i].getThreadGroup() == group) { buf.append("\n"); for (int j = 0; j < level + 1; j++) { buf.append(" "); } buf.append(t[i].getName()); buf.append(" (pri. "); buf.append(t[i].getPriority()); buf.append(")"); } } ThreadGroup[] g = new ThreadGroup[group.activeGroupCount()]; group.enumerate(g); for (int i = 0; g != null && i < g.length; i++) { buf.append("\n"); dumpThread(g[i], level + 1, buf); } }
From source file:haven.Utils.java
private static void dumptg(ThreadGroup tg, PrintWriter out, int indent) { for (int o = 0; o < indent; o++) out.print(" "); out.println("G: \"" + tg.getName() + "\""); Thread[] ths = new Thread[tg.activeCount() * 2]; ThreadGroup[] tgs = new ThreadGroup[tg.activeGroupCount() * 2]; int nt = tg.enumerate(ths, false); int ng = tg.enumerate(tgs, false); for (int i = 0; i < nt; i++) { Thread ct = ths[i];//from w w w .j av a 2 s . c om for (int o = 0; o < indent + 1; o++) out.print(" "); out.println("T: \"" + ct.getName() + "\""); } for (int i = 0; i < ng; i++) { ThreadGroup cg = tgs[i]; dumptg(cg, out, indent + 1); } }
From source file:ca.uviccscu.lp.server.main.ShutdownListener.java
public void threadReadout() { l.trace("Active thread readout"); ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) { tg = tg.getParent();/*from w w w . ja v a 2 s . c o m*/ } Thread[] threads = new Thread[tg.activeCount() + 1024]; tg.enumerate(threads, true); //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null) { l.trace("Thread " + i + " : " + th.getName()); } } }
From source file:com.agiletec.apsadmin.category.CategoryAction.java
/** * provide the result for the progress bar * @return/*from ww w. j ava2 s. c o m*/ */ public Map<String, Integer> getUpdateReferencesStatus() { int total = 0; int done = 0; ThreadGroup currentGroup = Thread.currentThread().getThreadGroup(); int numThreads = currentGroup.activeCount(); Thread[] listOfThreads = new Thread[numThreads]; currentGroup.enumerate(listOfThreads); for (int i = 0; i < numThreads; i++) { if (listOfThreads[i].getName() .startsWith(CategoryManager.RELOAD_CATEGORY_REFERENCES_THREAD_NAME_PREFIX)) { ReloadingCategoryReferencesThread thread = (ReloadingCategoryReferencesThread) listOfThreads[i]; total = total + thread.getListSize(); done = done + thread.getListIndex(); } } Map<String, Integer> result = new HashMap<String, Integer>(); result.put("total", total); result.put("done", done); return result; }
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); pGroup.setMaxPriority(Thread.MAX_PRIORITY - 2); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); cGroup.setMaxPriority(Thread.NORM_PRIORITY); Thread t1 = new Thread(pGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t1.getName()); t1.start();/*ww w. j ava2 s .c o m*/ Thread t2 = new Thread(cGroup, this); t1.setPriority(Thread.MAX_PRIORITY); System.out.println("Starting " + t2.getName()); t2.start(); System.out.println("Active threads in \"" + pGroup.getName() + "\" = " + pGroup.activeCount()); }
From source file:ca.uviccscu.lp.server.main.ShutdownListener.java
@Deprecated public void threadCleanup(File f) { while (!deleteFolder(f, false, 0, 0)) { l.error("Trying to stop more threads, list:"); //List remaining threads ThreadGroup tg2 = Thread.currentThread().getThreadGroup(); while (tg2.getParent() != null) { tg2 = tg2.getParent();/* w w w.j av a 2 s. co m*/ } //Object o = new Object(); //o.notifyAll(); Thread[] threads = new Thread[tg2.activeCount() + 1024]; tg2.enumerate(threads, true); //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null) { l.trace("Have thread: " + i + " : " + th.getName()); if (th != null && th != Thread.currentThread() && (AEThread2.isOurThread(th) || isAzThread(th))) { l.trace("Suspending " + th.getName()); try { th.suspend(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } } for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null) { l.trace("Have thread: " + i + " : " + th.getName()); if (th != null && th != Thread.currentThread() && (AEThread2.isOurThread(th) || isAzThread(th))) { l.trace("Stopping " + th.getName()); try { th.stop(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } } } System.gc(); }
From source file:org.apache.atlas.web.resources.AdminResource.java
/** * Fetches the thread stack dump for this application. * * @return json representing the thread stack dump. *//*w w w. j a v a2 s. com*/ @GET @Path("stack") @Produces(MediaType.TEXT_PLAIN) public String getThreadDump() { if (LOG.isDebugEnabled()) { LOG.debug("==> AdminResource.getThreadDump()"); } ThreadGroup topThreadGroup = Thread.currentThread().getThreadGroup(); while (topThreadGroup.getParent() != null) { topThreadGroup = topThreadGroup.getParent(); } Thread[] threads = new Thread[topThreadGroup.activeCount()]; int nr = topThreadGroup.enumerate(threads); StringBuilder builder = new StringBuilder(); for (int i = 0; i < nr; i++) { builder.append(threads[i].getName()).append("\nState: ").append(threads[i].getState()).append("\n"); String stackTrace = StringUtils.join(threads[i].getStackTrace(), "\n"); builder.append(stackTrace); } if (LOG.isDebugEnabled()) { LOG.debug("<== AdminResource.getThreadDump()"); } return builder.toString(); }