它们被用作一组线程.在一个简单的应用程序中,您只需要一个应用程序,但是在一个更复杂的应用程序服务器中,每个应用程序都有一个应用
why there is so little documentation about Thread Groups on the internet ?
我想有些人认为这是一个很简单的想法.不知道是什么缺失.
Are they still used or they are some stale concept ?
我会形象大多数开发人员不会考虑线程组.但我认为在某些情况下它们是有用的.我们有一个库,我们有一个自定义的ThreadGroup来重新设置线程亲和度.
Can some one explain that are they what they are used for, if still used, and give an example.
大多数在应用服务器中,每个服务器都有自己的线程集合,可以集中管理.如果要监视或关闭应用程序,您需要知道应用程序启动了哪些线程.
如果您从ThreadGroup中启动一个线程,则它创建的每个线程也将在该线程组中.没有此功能,您将很难将线程分配给应用程序.
From @biziclop: How do you reliably enumerate threads in a group?
您可以获得activeThreads的大小并枚举,因为ThreadGroup锁定在此(更好或更坏)
synchronized(threadGroup) {
Thread[] threads = threadGroup.activeCount();
threadGroup.enumerate(threads);
// use threads before the lock is released or it could be wrong.
}