Let’s look at this thread group. The name of the thread group is system, set the priority, and then specify that the parent thread is empty. You can see that this is the root thread group, and this method is private. , is not called for us.
Add the current thread to the thread group
Let’s try the above code logic, yes, no thread is specified The group will join the thread group of the currently created main thread. If the thread group is specified, it will be the current thread group.
The same is true when we look at the source code:
The number of active threads and active thread groups is both 0:
We have not opened the thread, so we need to open the thread. Here you can see the number of active threads:
Let's take a look at the source code. Here is the thread added to the thread group after it is started:
Then the thread is started to add and add, and the thread that is not started is subtracted.
Let’s experiment. We just added a sub-thread group, as follows:
At this time we can see that there can be another thread group under it Thread group
#That is to say, there can be threads or thread groups under the thread group.
Let’s take a look at the thread group of the main thread. The code is as follows:
#The thread group of the main thread is still main, and the parent thread group of the main thread is us When talking about system, this root thread group can have sub-threads and sub-thread groups below it, and so on.
The above is the detailed content of Java thread group construction method source code analysis. For more information, please follow other related articles on the PHP Chinese website!