Example usage for java.lang ThreadGroup getName

List of usage examples for java.lang ThreadGroup getName

Introduction

In this page you can find the example usage for java.lang ThreadGroup getName.

Prototype

public final String getName() 

Source Link

Document

Returns the name of this thread group.

Usage

From source file:org.bonitasoft.engine.LocalServerTestsInitializer.java

private boolean isExpectedThread(final Thread thread) {
    final String name = thread.getName();
    final ThreadGroup threadGroup = thread.getThreadGroup();
    if (threadGroup != null && threadGroup.getName().equals("system")) {
        return true;
    }/*ww w. j av a2s . co  m*/
    final List<String> startWithFilter = Arrays.asList("H2 ", "Timer-0" /* postgres driver related */, "BoneCP",
            "bitronix", "main", "Reference Handler", "Signal Dispatcher", "Finalizer",
            "com.google.common.base.internal.Finalizer"/* guava, used by bonecp */, "process reaper",
            "ReaderThread", "Abandoned connection cleanup thread", "AWT-AppKit"/* bonecp related */,
            "Monitor Ctrl-Break"/* Intellij */);
    for (final String prefix : startWithFilter) {
        if (name.startsWith(prefix)) {
            return true;
        }
    }
    return false;
}

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("  ");
    }/*from  w ww.ja  v a  2 s.c om*/
    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: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();/*  w  w w . j  ava  2s.c o m*/

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Active threads in " + pGroup.getName() + " = " + pGroup.activeCount());

    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: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 ww  w .j  av  a  2 s . co  m

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Active threads in \"" + pGroup.getName() + "\" = " + pGroup.activeCount());

}

From source file:org.codelibs.fess.servlet.Tomcat6ConfigServlet.java

@SuppressWarnings("deprecation")
private void cleanupAllThreads() {
    final Thread[] threads = getThreads();
    final ClassLoader cl = this.getClass().getClassLoader();
    try {/*  w ww .j  a  va 2 s. c o  m*/
        cl.getResource(null);
    } catch (final Exception e) {
    }

    final List<String> jvmThreadGroupList = new ArrayList<String>();
    jvmThreadGroupList.add("system");
    jvmThreadGroupList.add("RMI Runtime");

    // Iterate over the set of threads
    for (final Thread thread : threads) {
        if (thread != null) {
            final ClassLoader ccl = thread.getContextClassLoader();
            if (ccl != null && ccl.equals(cl)) {
                // Don't warn about this thread
                if (thread == Thread.currentThread()) {
                    continue;
                }

                // Don't warn about JVM controlled threads
                final ThreadGroup tg = thread.getThreadGroup();
                if (tg != null && jvmThreadGroupList.contains(tg.getName())) {
                    continue;
                }

                waitThread(thread);
                // Skip threads that have already died
                if (!thread.isAlive()) {
                    continue;
                }

                if (logger.isInfoEnabled()) {
                    logger.info("Interrupting a thread [" + thread.getName() + "]...");
                }
                thread.interrupt();

                waitThread(thread);
                // Skip threads that have already died
                if (!thread.isAlive()) {
                    continue;
                }

                if (logger.isInfoEnabled()) {
                    logger.info("Stopping a thread [" + thread.getName() + "]...");
                }
                thread.stop();
            }
        }
    }

    Field threadLocalsField = null;
    Field inheritableThreadLocalsField = null;
    Field tableField = null;
    try {
        threadLocalsField = Thread.class.getDeclaredField("threadLocals");
        threadLocalsField.setAccessible(true);
        inheritableThreadLocalsField = Thread.class.getDeclaredField("inheritableThreadLocals");
        inheritableThreadLocalsField.setAccessible(true);
        // Make the underlying array of ThreadLoad.ThreadLocalMap.Entry objects
        // accessible
        final Class<?> tlmClass = Class.forName("java.lang.ThreadLocal$ThreadLocalMap");
        tableField = tlmClass.getDeclaredField("table");
        tableField.setAccessible(true);
    } catch (final Exception e) {
        // ignore
    }
    for (final Thread thread : threads) {
        if (thread != null) {

            Object threadLocalMap;
            try {
                // Clear the first map
                threadLocalMap = threadLocalsField.get(thread);
                clearThreadLocalMap(cl, threadLocalMap, tableField);
            } catch (final Exception e) {
                // ignore
            }
            try { // Clear the second map
                threadLocalMap = inheritableThreadLocalsField.get(thread);
                clearThreadLocalMap(cl, threadLocalMap, tableField);
            } catch (final Exception e) {
                // ignore
            }
        }
    }
}

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();/*w  w  w .  j ava  2s  .c o m*/

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("ParentThreadGroup for " + pGroup.getName() + " is " + pGroup.getParent().getName());
    System.out.println("ParentThreadGroup for " + cGroup.getName() + " is " + cGroup.getParent().getName());

}

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. jav a 2s. c  om*/

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Active group(child) threads in \"" + pGroup.getName() + "\" = " + pGroup.activeCount());

}

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();//  w w w  .j  a va 2s . c o m

    Thread t2 = new Thread(cGroup, this);
    System.out.println("Starting " + t2.getName());
    t2.start();

    System.out.println("Listing parentThreadGroup: " + pGroup.getName());
    pGroup.list();

    System.out.println("Listing childThreadGroup : " + cGroup.getName());
    cGroup.list();

}

From source file:org.bonitasoft.engine.test.internal.EngineStarter.java

private boolean isExpectedThread(final Thread thread) {
    final String name = thread.getName();
    final ThreadGroup threadGroup = thread.getThreadGroup();
    if (threadGroup != null && threadGroup.getName().equals("system")) {
        return true;
    }/*from  ww  w  .  j a va2 s. c om*/
    final List<String> startWithFilter = Arrays.asList("H2 ", "Timer-0" /* postgres driver related */,
            "bitronix", "main", "Reference Handler", "Signal Dispatcher", "Finalizer",
            "com.google.common.base.internal.Finalizer", "process reaper", "ReaderThread",
            "Abandoned connection cleanup thread", "Monitor Ctrl-Break"/* Intellij */, "daemon-shutdown",
            "surefire-forkedjvm", "Restlet");
    for (final String prefix : startWithFilter) {
        if (name.startsWith(prefix)) {
            return true;
        }
    }
    //shutdown hook not executed in main thread
    return thread.getId() == Thread.currentThread().getId();
}

From source file:Main.java

public ThreadGroupDemo() {
    try {// www  .jav  a  2 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();

        pGroup.checkAccess();
        System.out.println(pGroup.getName() + " has access");
        cGroup.checkAccess();
        System.out.println(cGroup.getName() + " has access");
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}