List of usage examples for java.lang ThreadGroup getName
public final String getName()
From source file:Main.java
public ThreadGroupDemo() { ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup"); pGroup.setDaemon(true);//from ww w. jav a 2 s . c o m ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup"); cGroup.setDaemon(true); Thread t1 = new Thread(pGroup, this); System.out.println("Starting " + t1.getName()); t1.start(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); System.out.println("Is " + pGroup.getName() + " a daemon ThreadGroup? " + pGroup.isDaemon()); System.out.println("Is " + cGroup.getName() + " a daemon ThreadGroup? " + cGroup.isDaemon()); }
From source file:org.opencms.scheduler.CmsSchedulerThreadPool.java
/** * @see org.quartz.spi.ThreadPool#initialize() *//*from w w w . j a v a 2 s.co m*/ public void initialize() throws SchedulerConfigException { if ((m_maxThreadCount <= 0) || (m_maxThreadCount > 200)) { throw new SchedulerConfigException( Messages.get().getBundle().key(Messages.ERR_MAX_THREAD_COUNT_BOUNDS_0)); } if ((m_initialThreadCount < 0) || (m_initialThreadCount > m_maxThreadCount)) { throw new SchedulerConfigException( Messages.get().getBundle().key(Messages.ERR_INIT_THREAD_COUNT_BOUNDS_0)); } if ((m_threadPriority <= 0) || (m_threadPriority > 9)) { throw new SchedulerConfigException( Messages.get().getBundle().key(Messages.ERR_SCHEDULER_PRIORITY_BOUNDS_0)); } if (m_inheritGroup) { m_threadGroup = Thread.currentThread().getThreadGroup(); } else { // follow the threadGroup tree to the root thread group m_threadGroup = Thread.currentThread().getThreadGroup(); ThreadGroup parent = m_threadGroup; while (!parent.getName().equals("main")) { m_threadGroup = parent; parent = m_threadGroup.getParent(); } m_threadGroup = new ThreadGroup(parent, this.getClass().getName()); } if (m_inheritLoader) { LOG.debug(Messages.get().getBundle().key(Messages.LOG_USING_THREAD_CLASSLOADER_1, Thread.currentThread().getName())); } // create the worker threads and start them m_workers = new CmsSchedulerThread[m_maxThreadCount]; for (int i = 0; i < m_initialThreadCount; ++i) { growThreadPool(); } }
From source file:com.brienwheeler.lib.concurrent.NamedThreadFactory.java
@Override public Thread newThread(Runnable target) { ThreadGroup threadGroup = this.threadGroup.get(); if (threadGroup == null) throw new IllegalStateException( "not allowed to call newThread() before calling setName() on " + getClass().getSimpleName()); log.debug("allocating new thread in " + getName()); Thread thread = new Thread(threadGroup, target, threadGroup.getName() + "-" + threadCount.incrementAndGet()); thread.setUncaughtExceptionHandler(uncaughtExceptionHandler.get()); return thread; }
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 . ja v a 2s . c o m Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); // determine which ThreadGroup is parent boolean isParent = pGroup.parentOf(cGroup); System.out.println(pGroup.getName() + " is the parent of " + cGroup.getName() + "? " + isParent); isParent = cGroup.parentOf(pGroup); System.out.println(cGroup.getName() + " is the parent of " + pGroup.getName() + "? " + isParent); }
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 www .j ava 2s . co m*/ 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:Main.java
public ThreadGroupDemo() { try {// ww w . j av a2 s . c o m 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(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); t1.join(); t2.join(); if (!cGroup.isDestroyed()) { cGroup.destroy(); } else { System.out.println(cGroup.getName() + " destroyed"); } // parent group destroyed if (!pGroup.isDestroyed()) { pGroup.destroy(); } else { System.out.println(pGroup.getName() + " destroyed"); } } catch (Exception ex) { System.out.println(ex.toString()); } }
From source file:Main.java
public ThreadGroupDemo() { try {//ww w. j av a2 s. com 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(); Thread t2 = new Thread(cGroup, this); System.out.println("Starting " + t2.getName()); t2.start(); // block until the other threads finish t1.join(); t2.join(); // child group destroyed cGroup.destroy(); System.out.println(cGroup.getName() + " destroyed"); // parent group destroyed pGroup.destroy(); System.out.println(pGroup.getName() + " destroyed"); } catch (InterruptedException ex) { System.out.println(ex.toString()); } }
From source file:com.symbian.driver.core.processors.HardwarePostProcessor.java
/** * @see java.lang.Thread#run()// w ww . ja 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: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();/*from w w 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:org.quartz.simpl.SimpleThreadPool.java
public void initialize() throws SchedulerConfigException { if (count <= 0) { throw new SchedulerConfigException("Thread count must be > 0"); }/*from w w w . jav a 2 s . co m*/ if (prio <= 0 || prio > 9) { throw new SchedulerConfigException("Thread priority must be > 0 and <= 9"); } if (isThreadsInheritGroupOfInitializingThread()) { threadGroup = Thread.currentThread().getThreadGroup(); } else { // follow the threadGroup tree to the root thread group. threadGroup = Thread.currentThread().getThreadGroup(); ThreadGroup parent = threadGroup; while (!parent.getName().equals("main")) { threadGroup = parent; parent = threadGroup.getParent(); } threadGroup = new ThreadGroup(parent, "SimpleThreadPool"); if (isMakeThreadsDaemons()) { threadGroup.setDaemon(true); } } if (isThreadsInheritContextClassLoaderOfInitializingThread()) { getLog().info( "Job execution threads will use class loader of thread: " + Thread.currentThread().getName()); } // create the worker threads and start them Iterator workerThreads = createWorkerThreads(count).iterator(); while (workerThreads.hasNext()) { WorkerThread wt = (WorkerThread) workerThreads.next(); wt.start(); availWorkers.add(wt); } }