修改锁的对象。

This commit is contained in:
zhouxy108 2023-07-18 18:02:35 +08:00
parent 7208aa5aae
commit 87ef8b4612

View File

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