Example usage for java.lang Thread getName

List of usage examples for java.lang Thread getName

Introduction

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

Prototype

public final String getName() 

Source Link

Document

Returns this thread's name.

Usage

From source file:Main.java

public ThreadGroupDemo() {
    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");

    ThreadGroup cGroup = new ThreadGroup(pGroup, "Child ThreadGroup");

    int i = pGroup.getMaxPriority();
    System.out.println("Maximum priority of ParentThreadGroup =" + i);

    Thread t1 = new Thread(pGroup, this);
    System.out.println("Starting " + t1.getName());
    t1.start();//from  w w w.  j a  va 2s  . com

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

}

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  w  w.j  a  v a  2 s.  com

    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);
    for (int i = 0; i < count; i++) {
        System.out.println("ThreadGroup " + grpList[i].getName() + " found");
    }
}

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 v  a2  s . c  om*/

    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: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   www  .  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  w  ww  .j a  v  a  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:Main.java

public ThreadGroupDemo() {

    ThreadGroup pGroup = new ThreadGroup("Parent ThreadGroup");
    pGroup.setDaemon(true);//from  w  w  w.j  a va2 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: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   www  . ja  v  a 2  s .com

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

    Thread[] list = new Thread[pGroup.activeCount()];
    int count = pGroup.enumerate(list, true);
    for (int i = 0; i < count; i++) {
        System.out.println("Thread " + list[i].getName() + " found");
    }

}

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();/*ww w  . j a va2 s  .  co  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:MainClass.java

public MainClass() {
    Container cp = getContentPane();
    JButton crasher = new JButton("Crash");
    cp.add(crasher);/*from ww  w .  java  2s  . c  om*/
    crasher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            throw new RuntimeException("You asked for it");
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable ex) {
            System.out.println("You crashed thread " + t.getName());
            System.out.println("Exception was: " + ex.toString());
        }
    });
    pack();
}

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 www. j  a  va 2 s  .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);

}