ThreadGroup
Based on functionality we can group threads as a single unit which is nothing but ThreadGroup.
ThreadGroup provides a convenient way to perform common operations for all threads belongs to a particular group.
We can create a ThreadGroup by using the following constructors
ThreadGroup g = new ThreadGroup(String gName);
We can attach a Thread to the ThreadGroup by using the following constructor of Thread class
Thread t = new Thread(ThreadGroup g, String name);
ThreadGroup tgroup = new ThreadGroup("Printing Threads"); MyThread t1=new MyThread(tgroup,"Header Printing"); MyThread t2=new MyThread(tgroup,"Footer Printing"); MyThread t3=new MyThread(tgroup,"Body Printing"); ----------- tgroup.stop();
Note
Java Multi Threading concept is implementing by using the following 2 methods :
- GreenThread Model
- Native OS Model
GreenThread Model
The threads which are managed completely by JVM without taking support for underlying OS, such type of threads are called Green Threads.
Native OS Model
- The Threads which are managed with the help of underlying OS are called Native Threads.
- Windows based OS provide support for Native OS Model
- Very few OS like SunSolaries provide support for GreenThread Model
- Anyway GreenThread model is deprecated and not recommended to use.
ThreadGroup