Home Tutorial Java Core Java Thread : ThreadGroup

 
 

Share on Google+Share on Google+
Java Thread : ThreadGroup
Posted on: October 23, 2012 at 12:00 AM
Advertisement
In this tutorial, you will learn how to use ThreadGroup with example in Java.

Java Thread : ThreadGroup

In this tutorial, you will learn how to use ThreadGroup with example in Java.

getThreadGroup :

Every Java thread belongs to a thread group. Thread group treats all multiple threads into a single object and perform operations on all threads at once.The default thread group is main created by the JVM when first java application is started.

public final ThreadGroup getThreadGroup() : This method returns the thread group of threads to which they belongs. If thread die then it will return null.

Example : In this example we are using ThreadGroup.

public class ThreadGroupExample implements Runnable {

    Thread thread;
    ThreadGroup threadGroup;

    ThreadGroupExample() {
    	threadGroup = new ThreadGroup("Thread Group Example");
        thread = new Thread(threadGroup, this);
        thread.start();
    }

    public void run() {
        System.out.println(thread.getThreadGroup());
    }

    public static void main(String[] args) {
        new ThreadGroupExample();
        
    }
}

Output :

java.lang.ThreadGroup[name=Thread Group Example,maxpri=10]
Advertisement

Related Tags for Java Thread : ThreadGroup :


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2012

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com