Example usage for java.lang ThreadGroup list

List of usage examples for java.lang ThreadGroup list

Introduction

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

Prototype

public void list() 

Source Link

Document

Prints information about this thread group to the standard output.

Usage

From source file:NewThread.java

public static void main(String args[]) {
    ThreadGroup groupA = new ThreadGroup("Group A");
    ThreadGroup groupB = new ThreadGroup("Group B");

    NewThread ob1 = new NewThread("One", groupA);
    NewThread ob2 = new NewThread("Two", groupA);
    NewThread ob3 = new NewThread("Three", groupB);
    NewThread ob4 = new NewThread("Four", groupB);

    groupA.list();
    groupB.list();/*from   w  ww  .  ja v  a2  s .co  m*/
    Thread tga[] = new Thread[groupA.activeCount()];
    groupA.enumerate(tga);
    for (int i = 0; i < tga.length; i++) {
        ((NewThread) tga[i]).mysuspend();
    }

    try {
        Thread.sleep(4000);
    } catch (InterruptedException e) {
        System.out.println("Main thread interrupted.");
    }

    System.out.println("Resuming Group A");
    for (int i = 0; i < tga.length; i++) {
        ((NewThread) tga[i]).myresume();
    }

    try {
        ob1.join();
        ob2.join();
        ob3.join();
        ob4.join();
    } catch (Exception e) {
        System.out.println("Exception in Main thread");
    }
}

From source file:MyThread.java

public static void main(String args[]) {
    ThreadGroup groupA = new ThreadGroup("Group A");
    ThreadGroup groupB = new ThreadGroup("Group B");

    MyThread ob1 = new MyThread("One", groupA);
    MyThread ob2 = new MyThread("Two", groupA);
    MyThread ob3 = new MyThread("Three", groupB);
    MyThread ob4 = new MyThread("Four", groupB);

    System.out.println("\nHere is output from list():");
    groupA.list();
    groupB.list();//  w w  w .j av a 2 s .  c  om

    System.out.println("Suspending Group A");
    Thread tga[] = new Thread[groupA.activeCount()];
    groupA.enumerate(tga); // get threads in group
    for (int i = 0; i < tga.length; i++) {
        ((MyThread) tga[i]).suspendMe(); // suspend each thread
    }

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        System.out.println("Main thread interrupted.");
    }

    System.out.println("Resuming Group A");
    for (int i = 0; i < tga.length; i++) {
        ((MyThread) tga[i]).resumeMe();
    }

    try {
        System.out.println("Waiting for threads to finish.");
        ob1.join();
        ob2.join();
        ob3.join();
        ob4.join();
    } catch (Exception e) {
        System.out.println("Exception in Main thread");
    }
    System.out.println("Main thread exiting.");
}

From source file:ioheater.ui.IOHeaterUI.java

/**
 * Utility method for checking active threads.
 *//*from ww w . j a  v  a  2  s .com*/
public static void checkThreads() {
    ThreadGroup mainThreadGroup = Thread.currentThread().getThreadGroup();
    ThreadGroup systemThreadGroup = mainThreadGroup.getParent();

    logger.log(Level.INFO, "Current thread: {0}", Thread.currentThread());
    systemThreadGroup.list();
}

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  .  jav a2  s  .  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();

}