ThreadGroup.activeCount() Returns an estimate of the number of active threads in this thread group. 这个方法是把sleep的Thread也算在内的。你只能对每个Thread做手脚了,定义一个runningSize,Thread在运行的时候runningSize++,在sleep()之前runningSize--.
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.
Returns an estimate of the number of active threads in this thread group.
这个方法是把sleep的Thread也算在内的。你只能对每个Thread做手脚了,定义一个runningSize,Thread在运行的时候runningSize++,在sleep()之前runningSize--.
看看,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.