From 87ef8b4612ecc7720e1947966fa4b5437de65d83 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 18 Jul 2023 18:02:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=81=E7=9A=84=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java b/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java index e40a988..76f73f7 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/IdGenerator.java @@ -49,7 +49,8 @@ public class IdGenerator { public static SnowflakeIdGenerator getSnowflakeIdGenerator(long workerId, long datacenterId) { SnowflakeIdGenerator generator = snowflakePool.get(workerId, datacenterId); if (generator == null) { - synchronized (IdGenerator.class) { + // 其它地方需注意,对 snowflakePool 的操作,也都锁 snowflakePool 对象。 + synchronized (snowflakePool) { generator = snowflakePool.get(workerId, datacenterId); if (generator == null) { generator = new SnowflakeIdGenerator(workerId, datacenterId);