-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.2.0
-
sparc
-
solaris_2.4
Name: akC45999 Date: 09/29/97
The specification of Thread.enumerate(Thread[]) method says that
only active threads are taken into account. However, jdk12M seems
to count inactive threads also.
// test is derived from javasoft.sqe.tests.api.java.lang.Thread.enumerate0101
import java.io.PrintStream;
class enumerate0101t extends Thread {
boolean act; // must stay active?
ThreadGroup group;
enumerate0101t(ThreadGroup group, boolean act) {
super(group, String.valueOf(act));
this.group=group;
this.act=act;
}
public void run() {
if (!act) { return;}
synchronized(group) {
try {
group.wait();
} catch (InterruptedException e) {
}
}
}
} // end class enumerate0101t
public class enumerate0101 { //implements Test {
public static void main(String args[]) {
ThreadGroup group=new ThreadGroup("enumerate0101");
// create 1 active and 2 inactive threads in this group:
Thread activeThrd, nonActiveThrd1, nonActiveThrd2;
activeThrd=new enumerate0101t(group, true);
activeThrd.start();
nonActiveThrd1=new enumerate0101t(group, false);
nonActiveThrd1.start();
nonActiveThrd2=new enumerate0101t(group, false); // no start
try {
nonActiveThrd1.join();
} catch (InterruptedException e) {
}
// call Thread.enumerate():
Thread tarray[]=new Thread[10];
int cnt0=activeThrd.enumerate(tarray);
System.err.println("activeThrd.enumerate()="+cnt0);
// make activeThrd to finish:
synchronized(group) {
group.notify();
}
}
}
Running the test:
novo37% javac enumerate0101.java
novo37% setenv CLASSPATH .
novo37% java enumerate0101
activeThrd.enumerate()=3
======================================================================
The specification of Thread.enumerate(Thread[]) method says that
only active threads are taken into account. However, jdk12M seems
to count inactive threads also.
// test is derived from javasoft.sqe.tests.api.java.lang.Thread.enumerate0101
import java.io.PrintStream;
class enumerate0101t extends Thread {
boolean act; // must stay active?
ThreadGroup group;
enumerate0101t(ThreadGroup group, boolean act) {
super(group, String.valueOf(act));
this.group=group;
this.act=act;
}
public void run() {
if (!act) { return;}
synchronized(group) {
try {
group.wait();
} catch (InterruptedException e) {
}
}
}
} // end class enumerate0101t
public class enumerate0101 { //implements Test {
public static void main(String args[]) {
ThreadGroup group=new ThreadGroup("enumerate0101");
// create 1 active and 2 inactive threads in this group:
Thread activeThrd, nonActiveThrd1, nonActiveThrd2;
activeThrd=new enumerate0101t(group, true);
activeThrd.start();
nonActiveThrd1=new enumerate0101t(group, false);
nonActiveThrd1.start();
nonActiveThrd2=new enumerate0101t(group, false); // no start
try {
nonActiveThrd1.join();
} catch (InterruptedException e) {
}
// call Thread.enumerate():
Thread tarray[]=new Thread[10];
int cnt0=activeThrd.enumerate(tarray);
System.err.println("activeThrd.enumerate()="+cnt0);
// make activeThrd to finish:
synchronized(group) {
group.notify();
}
}
}
Running the test:
novo37% javac enumerate0101.java
novo37% setenv CLASSPATH .
novo37% java enumerate0101
activeThrd.enumerate()=3
======================================================================
- relates to
-
JDK-4189292 (thread spec) ThreadGroup and Thread need better and tighter specs
- Closed
-
JDK-4162694 (thread) ThreadGroup.activeCount() doesn't always reach 0 after stop() called
- Closed
-
JDK-4229558 (thread) ThreadGroup.activeCount vs ThreadGroup.enumerate on 1.1 vs 1.2
- Closed