You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2022/04/21 02:26:21 UTC

[shardingsphere] branch master updated: Optimize UUID performance (#16959)

This is an automated email from the ASF dual-hosted git repository.

wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f4fb4f8a7d Optimize UUID performance (#16959)
0f4fb4f8a7d is described below

commit 0f4fb4f8a7ddd4b2c53a9c3753cfef0b3c1de66b
Author: sunhangda <lw...@126.com>
AuthorDate: Thu Apr 21 10:26:09 2022 +0800

    Optimize UUID performance (#16959)
    
    * Optimize UUID performance
---
 .../sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java        | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java
index 5963b53c638..4a397829f2e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/algorithm/keygen/UUIDKeyGenerateAlgorithm.java
@@ -17,9 +17,11 @@
 
 package org.apache.shardingsphere.sharding.algorithm.keygen;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm;
 
 import java.util.UUID;
+import java.util.concurrent.ThreadLocalRandom;
 
 /**
  * UUID key generate algorithm.
@@ -31,8 +33,9 @@ public final class UUIDKeyGenerateAlgorithm implements KeyGenerateAlgorithm {
     }
     
     @Override
-    public synchronized Comparable<?> generateKey() {
-        return UUID.randomUUID().toString().replaceAll("-", "");
+    public Comparable<?> generateKey() {
+        ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current();
+        return StringUtils.replace(new UUID(threadLocalRandom.nextLong(), threadLocalRandom.nextLong()).toString(), "-", "");
     }
     
     @Override