修改锁的对象。

feature/net-util
ZhouXY108 2023-07-18 18:02:35 +08:00
parent 7208aa5aae
commit 87ef8b4612
1 changed files with 2 additions and 1 deletions

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