Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-459

Issue in HashCodeBuilder which only shows up under high load multi-threaded usage.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4
    • 2.5
    • lang.builder.*
    • None
    • All

    Description

      We found we were having problems with HashCodeBuilder under multi-threaded high load.

      I narrowed this down to the following attached test case.

      When I dug into the code, I found the problem was solved by commenting out the isRegistered method (though this would break the infinite loop problem).
      ( I did a lot of other digging that I wont bore you with).

      So instead I replaced the HashSet with an ArrayList and just added the object, rather than the toIdentityHashCodeInteger(object)

      This results in about 5 lines of change.

      My suspicion is that System.identityHashCode does not return unique values (it is after all a hashcode method). The code assumes it will return a unique value and this causes the problem at high loads.

      The downside is a List vs. a Set, but I believe this is necessary.

      I'd like to submit this fix and have it verified (and perhaps improved). I am convinced it is a necessary fix which we have seen show up under high loads.

      Kindest regards,
      Andrew.

      Attachments

        1. MyTest.java
          2 kB
          Andrew Wilson
        2. HashCodeBuilder.java
          31 kB
          Andrew Wilson

        Activity

          People

            Unassigned Unassigned
            anewilson7272 Andrew Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified