List of usage examples for java.lang ThreadGroup enumerate
public int enumerate(ThreadGroup list[], boolean recurse)
From source file:com.symbian.driver.core.processors.HardwarePostProcessor.java
/** * @see java.lang.Thread#run()//w w w .j a va2 s . c o m */ public void run() { LOGGER.info("Stopping and cleaning after TestDriver."); try { Runtime.getRuntime().removeShutdownHook(this); } catch (Exception lException) { LOGGER.fine("Didn't succefully deregister the shutdownhook."); } //uninstall tef before stop communication channel try { if (iTefDeps != null) { TDConfig CONFIG = TDConfig.getInstance(); boolean lPlatSec = true; try { //lPlatSec = CONFIG.isPreference(TDConfig.PLATSEC) && !CONFIG.isPreference(TDConfig.SYS_BIN); lPlatSec = !CONFIG.isPreference(TDConfig.SYS_BIN); } catch (ParseException e) { LOGGER.log(Level.WARNING, "Could not get the configuration for PlatSec. Defaulting to ON"); } if (lPlatSec) { iTefDeps.uninstall(); LOGGER.fine("TEF dependencies package was successfully removed!"); } } } catch (TimeLimitExceededException e) { LOGGER.log(Level.WARNING, " Warning: TEF dependencies package " + "was not successfully removed!"); } try { DeviceCommsProxy.getInstance().stop(false); } catch (Exception lException) { LOGGER.log(Level.SEVERE, " Error ", lException); } // Move RDebug to the results folder if (iRDebugThread != null) { LOGGER.fine("Killing RDebug."); iRDebugThread.setM_Life(false); } // Stop all remaing JStat Threads ThreadGroup lRootThread = Thread.currentThread().getThreadGroup().getParent(); while (lRootThread.getParent() != null) { lRootThread = lRootThread.getParent(); } // Get all threads Thread[] lThreads = new Thread[50]; int lNumThreads = lRootThread.enumerate(lThreads, true); LOGGER.fine( "The root thread is: " + lRootThread.getName() + "; and has " + lNumThreads + " children threads."); // Find any JStat threads remaining for (int lIter = 0; lIter < lNumThreads; lIter++) { LOGGER.fine("Looking at Thread: " + lThreads[lIter].getName()); if (lThreads[lIter].getName().indexOf("JStat") >= 0) { //|| lThreads[lIter].getName().indexOf("Timer") >= 0) { LOGGER.log(Level.SEVERE, "Could not stop all JStat Threads therefore killing TestDriver. Please check your Hardware or Emulator for failures."); } } LOGGER.exiting(HardwarePostProcessor.class.getName(), "run"); }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
private int getThreadCount(RequestProcessor requestProcessor, State state) { ThreadGroup threadGroup = requestProcessor.getThreadPool().getFactory().getGroup(); Thread[] threads = new Thread[threadGroup.activeCount()]; threadGroup.enumerate(threads, false); int threadCount = 0; for (Thread t : threads) { if (state == t.getState()) { threadCount++;/*from w w w .j a v a 2s . com*/ } } return threadCount; }
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start();/*from w ww .j a va 2s . c o m*/ Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); ThreadGroup[] grpList = new ThreadGroup[pGroup.activeGroupCount()]; int count = pGroup.enumerate(grpList, true); for (int i = 0; i < count; i++) { System.out.println("ThreadGroup" + grpList[i].getName() + " found"); } }
From source file:com.dianping.dpsf.jmx.DpsfResponsorMonitor.java
private String getThreadStackTraces(RequestProcessor requestProcessor, State state, int threadCount) { ThreadGroup threadGroup = requestProcessor.getThreadPool().getFactory().getGroup(); Thread[] threads = new Thread[threadGroup.activeCount()]; threadGroup.enumerate(threads, false); StringBuilder builder = new StringBuilder(); int count = 0; if (threads != null && threads.length > 0 && threadCount > 0) { for (Thread thread : threads) { if (state == thread.getState()) { count++;/*from w ww . ja v a2s . c o m*/ if (count > 1) { builder.append("\r\n\r\n"); } builder.append("Thread ").append(thread.getId()).append(" ").append(thread.getName()) .append(" (state = ").append(state).append(")").append("\r\n"); StackTraceElement[] stackTrace = thread.getStackTrace(); for (StackTraceElement ste : stackTrace) { builder.append(ste.getClassName()).append("-").append(ste.getMethodName()).append("(") .append(ste.getLineNumber()).append(")").append("\r\n"); } if (count >= threadCount) { break; } } } } return builder.toString(); }
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();/* w ww . j a v a 2 s . c om*/ } 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: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 a va 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
@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 ww. ja v a 2 s . c o 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.kaaproject.kaa.server.common.thrift.cli.server.BaseCliThriftService.java
/** * Retrieve all threads info from thread group. * * @param group the thread group/*from www .j ava2s . com*/ * @param threadsMap the threads map to store threads info */ private void allThreadsFromGroup(ThreadGroup group, Map<Long, ThreadStruct> threadsMap) { int threadCount = group.activeCount(); int groupCount = group.activeGroupCount(); Thread[] groupThreads = new Thread[threadCount]; ThreadGroup[] threadGroups = new ThreadGroup[groupCount]; group.enumerate(groupThreads, false); group.enumerate(threadGroups, false); for (Thread t : groupThreads) { if (t != null) { ThreadStruct ts = threadsMap.get(t.getId()); ts.thread = t; } } for (ThreadGroup tg : threadGroups) { allThreadsFromGroup(tg, threadsMap); } }
From source file:org.sakaiproject.status.StatusServlet.java
protected void printThreadGroupDetails(ThreadGroup g, String indent, HttpServletResponse response) throws Exception { PrintWriter pw = response.getWriter(); ThreadGroup parent = g.getParent(); String parentName = ""; if (parent != null) { parentName = parent.getName();/*from ww w .j a v a 2s. c o m*/ } int threadCount = g.activeCount(); int groupCount = g.activeGroupCount(); pw.print(indent + g.getName() + "," + parentName + "," + threadCount + "," + groupCount + "\n"); if (groupCount > 0) { ThreadGroup[] children = new ThreadGroup[groupCount]; g.enumerate(children, false); for (ThreadGroup child : children) { if (child != null) { printThreadGroupDetails(child, indent + " ", response); } } } }
From source file:com.lfv.lanzius.application.Controller.java
private synchronized void dbgListThreads() { if (!Config.DEBUG) return;//from ww w .java2 s . co m System.out.println("--------------------------------------------------"); System.out.println("Current thread: " + Thread.currentThread()); System.out.println("Active main threads:"); // Get threads in `group' ThreadGroup group = Thread.currentThread().getThreadGroup(); int numThreads = group.activeCount(); Thread[] threads = new Thread[numThreads * 2]; numThreads = group.enumerate(threads, false); // Enumerate each thread in `group' for (int i = 0; i < numThreads; i++) { // Get thread Thread thread = threads[i]; System.out.println(" " + thread); } System.out.println("--------------------------------------------------"); }