|
Quick Lists
|
|
Bug ID:
|
4089701
|
|
Votes
|
2
|
|
Synopsis
|
(thread) ThreadGroup.activeCount() counts non-started threads
|
|
Category
|
java:classes_lang
|
|
Reported Against
|
1.2
, 1.2beta3
, tiger-beta
|
|
Release Fixed
|
1.5(tiger-b32)
|
|
State
|
10-Fix Delivered,
Verified,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
5060834
|
|
Submit Date
|
30-OCT-1997
|
|
Description
|
Specification of class java.lang.ThreadGroup reads:
public static int activeCount()
Returns the current number of active threads in this thread group.
Sun's JDK 1.1 ... 1.2q activeCount() counts also the threads which was not
started yet (see the test).
[The spec doesn't explicitly states that a thred which is not started is not active,
but does it implicitly, in the spec of the ThreadGroup.setDaemon() method].
------------------------------------- file activeCount0101.java
// simplified version of the test
// javasoft.sqe.tests.api.java.lang.ThreadGroup.activeCount0101;
import java.io.PrintStream;
class activeCount0101r implements Runnable {
boolean fin=false;
public synchronized void run() {
if (fin) return;
try {
wait();
} catch (InterruptedException e) {
}
}
synchronized void finish() {
fin=true;
notifyAll();
}
} // end class activeCount0101r
class activeCount0101 extends ThreadGroup {
static final int activeNum=1; // active threads in each group
activeCount0101() {
super("activeCount0101");
}
public void test() {
activeCount0101r event=new activeCount0101r();
Thread activeThrd=new Thread(this, event, "activeCount0101_a")
, nonActiveThrd=new Thread(this, event, "activeCount0101_n")
;
activeThrd.start();
int cnt=activeCount();
event.finish();
if (cnt != activeNum)
System.out.println("activeNum:"+activeNum+" activeCount():"+cnt);
}
public static void main(String args[]) {
activeCount0101 group=new activeCount0101();
group.test();
}
} // end class activeCount0101
------------------------------------- end of file activeCount0101.java
Running the test:
novo64% javac activeCount0101.java
novo64% setenv CLASSPATH .
novo64% java activeCount0101
activeNum:1 activeCount():2
novo64%
======================================================================
In addition to ThreadGroup, I found the same problem with the
activeCount() method in the Thread class. I attached two files -
NeverStartedThreads.java and NeverStartedThreads.pass , a test and its
golden file - to illustrate the problem in more detail.
|
|
Work Around
|
N/A
|
|
Evaluation
|
It's not clear whether we should change the meaning of "active" at this point. If we elect to leave things as they stand, we should document it.
xxxxx@xxxxx 2002-11-08
Thread changes in Tiger make activeCount ignore unstarted Threads. activeCount() and enumerate will report only started threads.
xxxxx@xxxxx 2003-11-24
|
|
Comments
|
Submitted On 02-JUN-1998
jon_seymour
Agreed. However, API specification doesn't specify what an "active"
as opposed to "alive" thread is.
If "active" and "alive" are synonyms, then they should be
counted as active if and only if the "isAlive()" property is true
when tested.
If "active" is different to "alive", then a proper
specification of what "active" means should be specified.
Submitted On 08-APR-2003
dynaxis
As specified in other bugs such as #4229558, we definitely
need a mean to get list of even unstarted threads. Thus
please confirm the meaning of "active" as "unstarted or alive".
And add other methods for getting information on alive
threads.
Though it doesn't seem so critical, actually it is causing many
confusions.
- JDK 1.1 & 1.2 differ in their behavior.
- activeCount() and enumerate() respect different definitions
of active thread.
- Some open source, independent implementation
follows "active == alive".
Please at least fix the meaning of active thread. It would be
good if it is "unstarted or alive".
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |