Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • ThreadGroup Class

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 427
    Comment on it

    ThreadGroup in Java:

    It represents combination of threads within a group. A thread group can also include other thread groups .With the help of thread group we can easily suspend, resume or interrupt group of threads by a single method call.


    It is implemented by java.lang.ThreadGroup class.


        public class ThreadDemo implements Runnable{  
            public void run() {  
           public static void main(String[] args) {  
              ThreadDemo runnable = new ThreadDemo();  
                  ThreadGroup tg1 = new ThreadGroup("Parent ThreadGroup"); //creating new group named Parent ThreadGroup 
                  Thread t1 = new Thread(tg1, runnable,"one");  
                  Thread t2 = new Thread(tg1, runnable,"two");  
                  Thread t3 = new Thread(tg1, runnable,"three");  
                  System.out.println("Thread Group Name: "+tg1.getName());  


    Thread Group Name: Parent ThreadGroup
    java.lang.ThreadGroup[name=Parent ThreadGroup,maxpri=10]
        Thread[one,5,Parent ThreadGroup]
        Thread[two,5,Parent ThreadGroup]
        Thread[three,5,Parent ThreadGroup]

    In the above program we are creating a new thread group named Parent ThreadGroup which contains three threads (One,Two and Three) with priority 5.

    By default  Java runtime system creates a ThreadGroup named main. Unless specified , all new threads that are created become members of the main thread group.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: