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

UUIDGenerator generates same ID multiple times when invoked from multiple threads

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None
    • Ubuntu 6.06, JDK 1.5

    Description

      org.apache.axiom.om.util.UUIDGenerator generates same UUID more than once, when the UUIDGenerator.getUUID() is invoked from multiple threads concurrently. I have tested this with 100 threads, each invoking the getUUID() 1000 times. UUIDGenerator generates about 1500 to 3000 same IDs for 100000 invocations.

      I am listing the code I have used to test this below:

      package uuidtest;

      import org.apache.axiom.om.util.UUIDGenerator;

      import java.util.*;

      public class UUIDGenTest {

      private static final int THREADS = 100;
      private static final int ITERATIONS = 1000;

      Map generatedIds = Collections.synchronizedMap(new HashMap());
      int errorCount = 0;
      Object lock = new Object();

      public static void main(String[] args)

      { new UUIDGenTest().test(); }

      public void test() {

      Thread[] threads = new Thread[THREADS];
      for (int i = 0; i < THREADS; i++)

      { threads[i] = new Thread(new Generate()); threads[i].start(); }

      for (int i = 0; i < THREADS; i++) {
      try

      { threads[i].join(); }

      catch (InterruptedException e)

      { e.printStackTrace(); }

      }
      System.out.println("=======================================================");
      System.out.println(" Error count : " + errorCount + " for " + THREADS * ITERATIONS);
      System.out.println("=======================================================");
      }

      class Generate implements Runnable {
      public void run() {
      for (int i=0; i<ITERATIONS; i++) {
      String id = UUIDGenerator.getUUID();
      if (generatedIds.containsKey(id)) {
      System.out.println("ERROR - Same UUID has been generated before. UUID: " + id);
      synchronized(lock)

      { errorCount++; }

      }
      generatedIds.put(id, Thread.currentThread().getName());
      }
      }
      }
      }

      If you compile and run this with AXIOM jars in the classpath, you could observe an error count about 1500 to 3000.

      Attachments

        Issue Links

          Activity

            People

              eran chinthaka Eran Chinthaka
              ccekanayake Chathura Ekanayake
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: