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

(thread) ThreadGroup.activeCount vs ThreadGroup.enumerate on 1.1 vs 1.2



    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.2.0, 1.3.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
    • OS:


      Name: vi73552 Date: 04/14/99

      1. Exact steps ...

      1) Create a thread group.
      2) Add some threads to it.
      3) Start some of them.
      4) Get active Thread count.
      5) Get enumeration of ThreadGroup.
      6) Step through the enumeration and start the ones that return
         false for isAlive.

      You can't do this on Java 1.2 because the enumeration only
      returns the threads that return true for isAlive.

      2. Java SOURCE CODE ...
      ThreadGroup tg = new ThreadGroup("group1");
      Thread[] t = new Thread[3];
      t[0] = new Thread(tg,r[0],"thread"+0);
      t[1] = new Thread(tg,r[1],"thread"+1); t[1].start();
      t[2] = new Thread(tg,r[2],"thread"+2);

      int count = tg.activeCount();
      Thread[] a = new Thread[count];
      int active = tg.enumerate(a);

      for (int ndx = 0; ndx < active; ndx++)
          if (!active[ndx].isAlive())
              System.out.println("Thread already alive: " + active[ndx]);

      But this will only display that thread1 is already alive, and
      thread0 and thread2 will never get started.

      5. The out put of commands ...

      java version "1.2"
      Classic VM (build JDK-1.2-V, native threads)

      java full version "JDK-1.2-V"
      (Review ID: 56516)

      Name: boT120536 Date: 01/30/2001

      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

      ThreadGroup tg=new ThreadGroup("unstoppable");
      Thread t1=new Thread(tg,"thread1",runnable1);
      Thread t2=new Thread(tg,"thread2",runnable2);


      while (t1.isAlive()) try {Thread.sleep(1000);} catch (Throwable t) {;}

      try {
      } catch (IllegalThreadStateException itse) {
      /* This is because t2 has not been started, and cannot be disposed() */
        System.err.println("Expected Exception occured:");
      /* at this point you cannot enumerate which threads have not been started,
      and you cannot start them, enumerate them, discover anything about them. */
      } catch (Throwable t) {
        System.err.println("This was an unexpected error:");

      One must be able to guarantee the JVM will properly terminate without
      requiring a call to System.exit(), or Runtime.exit().

      In order to meet that requirement, all threads in existence must be daemon,
      and the JVM will examine _ALL_ threads.

      In Java, there is no reliable method to determine if System.exit() is

      There is no method available to see if there are any unstarted threads.

      Since the mechanism to get a full thread dump under program control was
      removed, this cannot be used to introspect the current state of the VM to
      determine if there are threads which have not been started, and thus
      determine if a System.exit() is required.

      When bugs are fixed, it is the nature of the problem, which determines what
      is implemented as a solution.

      In this particular case, I am concerned that the nature of the problem
      defined for Bug#4229558 will ignore the real problem.


      Ken Graham.
      (Review ID: 115893)


          Issue Links



              psoper Pete Soper (Inactive)
              vasya Vassili Igouchkine (Inactive)
              0 Vote for this issue
              0 Start watching this issue