java 建立线程组_什么是Java中的线程组?

它们被用作一组线程.在一个简单的应用程序中,您只需要一个应用程序,但是在一个更复杂的应用程序服务器中,每个应用程序都有一个应用

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.

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值