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++)
for (int i = 0; i < THREADS; i++) {
try
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)
}
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
- relates to
-
WSS-221 UUIDGenerator generates duplicate identifiers when used in a multi-threaded environment
- Closed