如何知道ThreadGroup中的活动线程数呢?
sleep的不算
只有正在运行的线程数量,
请高手帮忙。
多谢。
问题点数:50、回复次数:11Top
1 楼javafaq2004(I will survive)回复于 2004-12-03 13:49:13 得分 5
好象有个类似active的方法Top
2 楼tom2005(随海奔跑)回复于 2004-12-03 13:52:42 得分 3
activeCountTop
3 楼xyzguan(不说)回复于 2004-12-03 13:54:14 得分 0
isActive是Thread的方法,莫非要我遍历?开销太大了:(Top
4 楼xyzguan(不说)回复于 2004-12-03 13:54:35 得分 0
activeCount是所有线程数吧?Top
5 楼javafaq2004(I will survive)回复于 2004-12-03 13:55:46 得分 0
记不清了,楼主测试一下看。Top
6 楼chubbchubb(长街)回复于 2004-12-03 13:58:57 得分 14
ThreadGroup.activeCount()
Returns an estimate of the number of active threads in this thread group.
这个方法是把sleep的Thread也算在内的。
你只能对每个Thread做手脚了,定义一个runningSize,Thread在运行的时候runningSize++,在sleep()之前runningSize--.
Top
7 楼chubbchubb(长街)回复于 2004-12-03 14:01:50 得分 14
sleep的thread的isActive,返回值也是true。
看看,JAVA Doc:
isAlive
public final boolean isAlive()
Tests if this thread is alive. A thread is alive if it has been started and has not yet died.
Returns:
true if this thread is alive; false otherwise.
Top
8 楼123xxx(香克斯)回复于 2004-12-03 14:09:45 得分 3
不会别的方法,也是觉得只能用chubbchubb(长街)的方法了,希望有高手给出更快的方法Top
9 楼xyzguan(不说)回复于 2004-12-03 14:12:41 得分 0
线程sleep的时候是什么状态?Top
10 楼xyzguan(不说)回复于 2004-12-04 10:11:04 得分 0
线程sleep的时候是什么状态?
Top
11 楼chubbchubb(长街)回复于 2004-12-06 11:27:59 得分 11
也是Active状态。Top




