You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by "Eran Chinthaka 2 (JIRA)" <ji...@apache.org> on 2007/05/07 05:57:15 UTC

[jira] Resolved: (WSCOMMONS-201) UUIDGenerator generates same ID multiple times when invoked from multiple threads

     [ https://issues.apache.org/jira/browse/WSCOMMONS-201?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eran Chinthaka 2 resolved WSCOMMONS-201.
----------------------------------------

    Resolution: Fixed
      Assignee: Eran Chinthaka

Well the problem was due to a synchronization issue. I did all the hacks some time back to this method as this was a hot spot for performance measurements. Since Chathura is keen getting this right, I am making it synchronized again. 
BTW, please remember that this is not a fully fledged UUID generator. Since this is a hot spot, we wanted to have a minimal version which is just enough for the system. 

> UUIDGenerator generates same ID multiple times when invoked from multiple threads
> ---------------------------------------------------------------------------------
>
>                 Key: WSCOMMONS-201
>                 URL: https://issues.apache.org/jira/browse/WSCOMMONS-201
>             Project: WS-Commons
>          Issue Type: Bug
>          Components: AXIOM
>         Environment: Ubuntu 6.06, JDK 1.5
>            Reporter: Chathura Ekanayake
>         Assigned To: Eran Chinthaka
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org