Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4082405

(thread) Thread.enumerate() yields wrong result (it counts inactive threads)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.2.0
    • core-libs
    • 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


      ======================================================================

            psoper Pete Soper (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: