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

(spec thread) Thread.activeCount spec is ambiguous

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b40
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: skR10005 Date: 06/11/2003


      The API specification of methods ThreadGroup.activeCount and
      ThreadGroup.activeGroupCount contain the word "estimate" which should be
      explained.

      According to explanation of jdk developers
        "these methods are ill-specified"
      but API users may expect some definite behaviour.
      The same concerns Thread.activeCount method.

      I agree with Jonathan Gibbons opinion that
        "If we are not formally deprecating these methods, would it not be worth
         amending the spec to point out the faults and to recommend against their
         usage. Otherwise, there will continue to be questions like this from
         people trying to use them."

      At the same time API spec for all ThreadGroup enumerate methods read
        "An application should use the activeCount method to get an estimate of
         how big the array should be."

      These asserion should be corrected too.
      Moreover according to explanation of jdk developers
        "This method is known not to work properly due to the (obvious) race
         condition: the number of threads can grow or shrink in between the two
         calls. This problem has been known since '95 (or so). It is disccussed
         in Item 52 of "Effective Java" among other places."
         
      I think that this clarification should be added to API spec too.

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

        Attachments

          Activity

            People

            Assignee:
            jjb Josh Bloch
            Reporter:
            serjsunw Serj Serj (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: