From 294a5e6b07d412b1bd14b0a300e1fefdc94a939b Mon Sep 17 00:00:00 2001 From: Steve Marion Date: Wed, 31 Jul 2024 10:40:56 +0200 Subject: SONAR-22649 make UuidFactoryFast use atomic counters for parallel execution support. --- sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java b/sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java index f19744c23ca..5d5aed897aa 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java +++ b/sonar-core/src/main/java/org/sonar/core/util/UuidFactoryFast.java @@ -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. */ -- cgit v1.2.3