]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-22649 make UuidFactoryFast use atomic counters for parallel execution support.
authorSteve Marion <steve.marion@sonarsource.com>
Wed, 31 Jul 2024 08:40:56 +0000 (10:40 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 12 Aug 2024 20:02:45 +0000 (20:02 +0000)
sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java

index f19744c23ca57291f7ada0e712d96215c78b155a..5d5aed897aadfa0281c58b556f588c44f19fd4b5 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.core.util;
 
 import java.security.SecureRandom;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * NOT thread safe
@@ -29,7 +30,7 @@ import java.security.SecureRandom;
 public class UuidFactoryFast implements UuidFactory {
   private static UuidFactoryFast instance = new UuidFactoryFast();
   private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
-  private static int sequenceNumber = new SecureRandom().nextInt();
+  private AtomicInteger sequenceNumber = new AtomicInteger(new SecureRandom().nextInt());
 
   private UuidFactoryFast() {
     //
@@ -54,8 +55,8 @@ public class UuidFactoryFast implements UuidFactory {
     return instance;
   }
   
-  private static int getSequenceNumber() {
-    return sequenceNumber++;
+  private int getSequenceNumber() {
+    return sequenceNumber.getAndIncrement();
   }
 
   /** Puts the lower numberOfLongBytes from l into the array, starting index pos. */