This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: ThreadGroup.enumerate
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Subject: Patch: ThreadGroup.enumerate
- From: Tom Tromey <tromey at redhat dot com>
- Date: 20 Feb 2001 11:15:44 -0700
- Reply-To: tromey at redhat dot com
I'm checking this in on the trunk, the branch, and Classpath. This
fixes a bug in ThreadGroup.enumerate(). The spec is a little unclear
here, but if you read between the lines you can see that only threads
which have been started should be listed by enumerate. Also, this is
what the JDK does.
I checked in a Mauve test case for this, and I verified that this
patch works against it.
2001-02-16 Tom Tromey <tromey@cygnus.com>
* java/lang/ThreadGroup.java (activeCount): Only include threads
which are alive.
(enumerate): Likewise.
Tom
Index: java/lang/ThreadGroup.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/ThreadGroup.java,v
retrieving revision 1.11
diff -u -r1.11 ThreadGroup.java
--- ThreadGroup.java 2000/10/25 08:11:47 1.11
+++ ThreadGroup.java 2001/02/20 18:03:57
@@ -1,5 +1,5 @@
/* java.lang.ThreadGroup
- Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -204,16 +204,21 @@
* @return the number of active threads in this ThreadGroup and
* its descendants.
* @specnote it isn't clear what the definition of an "Active" thread is.
- * Current JDKs regard all threads as active until they are
- * finished, regardless of whether the thread has been started
- * or not. We implement this behaviour.
- * There is open JDC bug, <A HREF="http://developer.java.sun.com/developer/bugParade/bugs/4089701.html">
+ * Current JDKs regard a thread as active if has been
+ * started and not finished. We implement this behaviour.
+ * There is a JDC bug, <A HREF="http://developer.java.sun.com/developer/bugParade/bugs/4089701.html">
* 4089701</A>, regarding this issue.
*
*/
public synchronized int activeCount()
{
- int total = threads.size();
+ int total = 0;
+ for (int i = 0; i < threads.size(); ++i)
+ {
+ if (((Thread) threads.elementAt(i)).isAlive ())
+ ++total;
+ }
+
for (int i=0; i < groups.size(); i++)
{
ThreadGroup g = (ThreadGroup) groups.elementAt(i);
@@ -274,7 +279,11 @@
{
Enumeration e = threads.elements();
while (e.hasMoreElements() && next_index < list.length)
- list[next_index++] = (Thread) e.nextElement();
+ {
+ Thread t = (Thread) e.nextElement();
+ if (t.isAlive ())
+ list[next_index++] = t;
+ }
if (recurse && next_index != list.length)
{
e = groups.elements();