Uploaded image for project: 'Axiom'
  1. Axiom
  2. AXIOM-390

Memory leak in UIDGenerator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Invalid
    • 1.2.12
    • None
    • API
    • None
    • Tomcat 7.0.21, Axis2 1.6.1 with Axiom 1.2.12

    Description

      Shutting down tomcat produces a list of error messages for each request of a web service:

      16.09.2011 08:36:16 org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
      SCHWERWIEGEND: The web application [/datatransfer] created a ThreadLocal with key of type [org.apache.axiom.util.UIDGenerator$1] (value [org.apache.axiom.util.UIDGenerator$1@252a78ee]) and a value of type [long[]] (value [[J@7696452]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.

      Problem seems to be ThreadLocal, which cannot bee cleaned up after processing the request. Eliminating ThreadLocal solves the problem:

      public final class UIDGenerator {
      // private static final long startTimeXorOperand;
      private static final long threadIdXorOperand;
      private static final long seqXorOperand;

      static

      { Random rand = new Random(); threadIdXorOperand = rand.nextLong(); // startTimeXorOperand = rand.nextLong(); seqXorOperand = rand.nextLong(); }

      private final static AtomicLong seqValue = new AtomicLong(0);

      private UIDGenerator() {
      }

      private static void writeReverseLongHex(long value, StringBuilder buffer) {
      for (int i = 0; i < 64; i += 4)

      { int n = (int) (value >> i) & 0xF; buffer.append((char) (n < 10 ? '0' + n : 'a' + n - 10)); }

      }

      /**

      • Generate a unique ID as hex value and add it to the given buffer. Note that
      • with respect to the triplet, the order of nibbles is reversed, i.e. the
      • least significant nibble of the sequence is written first. This makes
      • comparing two IDs for equality more efficient.
      • @param buffer
        */
        private static void generateHex(StringBuilder buffer) { writeReverseLongHex(seqValue.incrementAndGet() ^ seqXorOperand, buffer); writeReverseLongHex(Thread.currentThread().getId() ^ threadIdXorOperand, buffer); }

      ...

      Attachments

        Activity

          People

            Unassigned Unassigned
            detlef.guenther Detlef Günther
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: