简体   繁体   中英

What is active thread group in Java?

There is method java.lang.ThreadGroup.activeGroupCount() returns an estimate of the number of active groups in a thread group. In response to this question , the active thread is defined. But what does active thread group mean?

In Java there is a group abstraction around a group of threads, so it is easier to manage a group of threads. See eg Java: Thread Group

Every Java thread is a member of a thread group. Thread groups provide a mechanism for collecting multiple threads into a single object and manipulating those threads all at once, rather than individually.

For example, you can start or suspend all the threads within a group with a single method call. Java thread groups are implemented by the ThreadGroup(in the API reference documentation) class in the java.lang package.

As you noted, the terminology "active thread group" appears in the javadoc for ThreadGroup::activeGroupCount .

An active thread group is a ThreadGroup containing at least one active thread.

An active thread is one for which Thread::isAlive returns true . In other words, it has been started and has not yet terminated.


Note that thread groups are are only really suitable for debugging; see What is the benefit of ThreadGroup in java over creating separate threads? . For example, the enumerate method has this javadoc caveat:

"Due to the inherent race condition in this method, it is recommended that the method only be used for debugging and monitoring purposes."

This also applies to the "count" methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM