List of usage examples for java.lang ThreadGroup destroy
public final void destroy()
From source file:com.flexive.shared.cache.impl.FxJBossEmbeddedCacheProvider.java
/** * {@inheritDoc}/*from w w w . j a v a 2 s.com*/ */ @Override public void shutdown() throws FxCacheException { cache.getCache().stop(); cache.getCache().destroy(); final ThreadGroup group = org.jgroups.util.Util.getGlobalThreadGroup(); if (group.getClass().getClassLoader() == FxJBossEmbeddedCacheProvider.class.getClassLoader()) { // it seems that our JBoss cache instance created the group try { group.destroy(); } catch (Exception e) { if (LOG.isWarnEnabled()) { LOG.warn("Failed to shutdown JGroups thread group: " + e.getMessage(), e); } } } }
From source file:Main.java
public ThreadGroupDemo() { try {//w ww.jav a2 s . c om 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 {/*from ww w. ja va2 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(); // 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.meltmedia.cadmium.servlets.ClassLoaderLeakPreventor.java
/** * Destroy any ThreadGroups that are loaded by the application classloader */// ww w.j a va 2 s.c o m public void destroyThreadGroups() { try { ThreadGroup systemThreadGroup = Thread.currentThread().getThreadGroup(); while (systemThreadGroup.getParent() != null) { systemThreadGroup = systemThreadGroup.getParent(); } // systemThreadGroup should now be the topmost ThreadGroup, "system" int enumeratedGroups; ThreadGroup[] allThreadGroups; int noOfGroups = systemThreadGroup.activeGroupCount(); // Estimate no of groups do { noOfGroups += 10; // Make room for 10 extra allThreadGroups = new ThreadGroup[noOfGroups]; enumeratedGroups = systemThreadGroup.enumerate(allThreadGroups); } while (enumeratedGroups >= noOfGroups); // If there was not room for all groups, try again for (ThreadGroup threadGroup : allThreadGroups) { if (isLoadedInWebApplication(threadGroup) && !threadGroup.isDestroyed()) { warn("ThreadGroup '" + threadGroup + "' was loaded inside application, needs to be destroyed"); int noOfThreads = threadGroup.activeCount(); if (noOfThreads > 0) { warn("There seems to be " + noOfThreads + " running in ThreadGroup '" + threadGroup + "'; interrupting"); try { threadGroup.interrupt(); } catch (Exception e) { error(e); } } try { threadGroup.destroy(); info("ThreadGroup '" + threadGroup + "' successfully destroyed"); } catch (Exception e) { error(e); } } } } catch (Exception ex) { error(ex); } }