summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2001-02-20 18:09:23 +0000
committerTom Tromey <tromey@redhat.com>2001-02-20 18:09:23 +0000
commitd1cef00e0bf1e2678096aab77e1c371d45e8878a (patch)
tree0e24a1d16551a15d3f3dd3546855c8c543fb8b6b
parent4d03f9cf8e0df51d053863d2919f10bbe76d7636 (diff)
downloadclasspath-d1cef00e0bf1e2678096aab77e1c371d45e8878a.tar.gz
* java/lang/ThreadGroup.java (activeCount): Only include threads
which are alive. (enumerate): Likewise.
-rw-r--r--ChangeLog6
-rw-r--r--java/lang/ThreadGroup.java23
2 files changed, 22 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 648fa3939..095b221d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-02-16 Tom Tromey <tromey@cygnus.com>
+
+ * java/lang/ThreadGroup.java (activeCount): Only include threads
+ which are alive.
+ (enumerate): Likewise.
+
2001-02-18 Mark Wielaard <mark@klomp.org>
* java/util/ArrayList.java: Remove RCS keywords from comments
diff --git a/java/lang/ThreadGroup.java b/java/lang/ThreadGroup.java
index cf1e7171c..e8b444682 100644
--- a/java/lang/ThreadGroup.java
+++ b/java/lang/ThreadGroup.java
@@ -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 @@ public class ThreadGroup
* @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 @@ public class ThreadGroup
{
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();