Thread Constructors
Several constructors are available for creating new Thread instances.
All thread have only one thread group. And all thread groups (except the root thread group) belongs to exactly one parent thread group. Threads can access only belonging thread group.
When a new ThreadGroup is created, it is added as a member of existing ThreadGroup.
If a thread x in group1, and executes the code:
Some important methods are:
getName() – This method is used to retrieve the name of particular group.
- Thread()
- Thread(String)
- Thread(Runnable)
- Thread(Runnable,String)
- Thread(ThreadGroup,String)
- Thread(ThreadGroup,Runnable)
- Thread(ThreadGroup,Runnable,String)
- Thread(ThreadGroup, Runnable, String, long)
All thread have only one thread group. And all thread groups (except the root thread group) belongs to exactly one parent thread group. Threads can access only belonging thread group.
When a new ThreadGroup is created, it is added as a member of existing ThreadGroup.
If a thread x in group1, and executes the code:
Then the newly formed group2 comes under group1. If you want a parent group other than default then you have to specify the parent group at the time of creation.
- ThreadGroup group2=new ThreadGroup(“group2”);
Then newly formed group3 comes under the group2.
ThreadGroup group2=new ThreadGroup(group2,“group3”);
Some important methods are:
getName() – This method is used to retrieve the name of particular group.
ThreadGroup g=new ThreadGroup(“RoseIndia”);
- String gname=g.getName();
- ThreadGroup group=group3.getParent();
- int size=group.activeGroupCount();
- ThreadGroup group=threadx.getThreadGroup();
0 comments:
Post a Comment