| ||||
Copyright 1999 Sams Publishing |
|
Finding the Subgroups of a Thread Group |
The activeGroupCount() method returns the number of active thread groups in a particular ThreadGroup and all of its subgroups . Keep in mind that this can be dynamically changing, but its an accurate snapshot at a moment in time. |
To get a reference to all of the groups and subgroups of a ThreadGroup , the enumerate(ThreadGroup[]) method can be used. If you dont want to include a recursive search of the subgroups, use enumerate(ThreadGroup[], false) instead. Both methods return the number of groups copied into the array that is passed. If the array is not big enough, the extra groups are silently ignored. To get an idea of how big the destination array needs to be, you can use the value returned from activeGroupCount() . This code tries to capture all of the groups and subgroups of group : |
ThreadGroup group = // ... |
int estimatedSize = 2 * group. activeGroupCount (); |
ThreadGroup[] dest = new ThreadGroup[estimatedSize]; |
int actualSize = group. enumerate (dest); |
The count returned from activeGroupCount() is doubled in an attempt to be sure that the destination array is large enough. Based on estimatedSize , a destination array for the groups is allocated and referred to by dest . The enumerate(ThreadGroup[]) method copies up to dest.length groups into dest . The number of groups copied is returned and stored in actualSize . If actualSize is equal to dest.length , there is a good chance that dest was not big enough. Generally, actualSize is less than dest.length and indicates the number of valid groups in dest . |
| |||
Toc |