svn commit: r802498 - /camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r802498 - /camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java

davsclaus-2
Author: davsclaus
Date: Sun Aug  9 07:20:31 2009
New Revision: 802498

URL: http://svn.apache.org/viewvc?rev=802498&view=rev
Log:
A little tuning using AtomicLong instead of synchronized method when generating an unique id

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java?rev=802498&r1=802497&r2=802498&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java Sun Aug  9 07:20:31 2009
@@ -18,6 +18,7 @@
 
 import java.net.InetAddress;
 import java.net.ServerSocket;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -32,7 +33,7 @@
     private static int instanceCount;
     private static String hostName;
     private String seed;
-    private long sequence;
+    private AtomicLong sequence = new AtomicLong();
 
     static {
         String stub = "";
@@ -86,8 +87,8 @@
     /**
      * Generate a unqiue id
      */
-    public synchronized String generateId() {
-        return this.seed + (this.sequence++);
+    public String generateId() {
+        return this.seed + sequence.getAndIncrement();
     }
 
     /**