•If a program consists of large number of threads, we can divide them into groups and control each group as a whole.
•This can be achieved by using the predefined class in Java namely “ThreadGroup”.
•Every thread by default is assigned to a default group generally the “main” group.
•To create a new thread group, we must use the constructor of the “ThreadGroup” class. It is available in “java.lang” package.
•Following are the constructors in the “Threadgroup” class:
1) ThreadGroup(String Groupname)
2) ThreadGroup(ThreadGroup parent, String name)
•A thread must be assigned to a thread group, before calling the start() method of the thread. Once the start() method has been invoked, we cannot change the thread group.
•After creating a thread group, we can add threads to it by using the following constructors available in the “Thread” class:
1) Thread(ThreadGroup group, Runnable object)
2) Thread(ThreadGroup group, String name)
3) Thread(ThreadGroup group, Runnable object, String name)
•This can be achieved by using the predefined class in Java namely “ThreadGroup”.
•Every thread by default is assigned to a default group generally the “main” group.
•To create a new thread group, we must use the constructor of the “ThreadGroup” class. It is available in “java.lang” package.
•Following are the constructors in the “Threadgroup” class:
1) ThreadGroup(String Groupname)
2) ThreadGroup(ThreadGroup parent, String name)
•A thread must be assigned to a thread group, before calling the start() method of the thread. Once the start() method has been invoked, we cannot change the thread group.
•After creating a thread group, we can add threads to it by using the following constructors available in the “Thread” class:
1) Thread(ThreadGroup group, Runnable object)
2) Thread(ThreadGroup group, String name)
3) Thread(ThreadGroup group, Runnable object, String name)
No comments:
Post a Comment