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);