|
|
@@ -120,8 +120,9 @@ public class IdWorker { |
|
|
* @return SnowflakeId |
|
|
* @return SnowflakeId |
|
|
*/ |
|
|
*/ |
|
|
public synchronized long nextId() { |
|
|
public synchronized long nextId() { |
|
|
|
|
|
logger.info(">>>>>workerId start"); |
|
|
long timestamp = timeGen(); |
|
|
long timestamp = timeGen(); |
|
|
|
|
|
|
|
|
|
|
|
logger.info(">>>>>workerId timestamp"+timestamp); |
|
|
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常 |
|
|
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常 |
|
|
if (timestamp < lastTimestamp) { |
|
|
if (timestamp < lastTimestamp) { |
|
|
throw new RuntimeException( |
|
|
throw new RuntimeException( |
|
|
@@ -141,7 +142,7 @@ public class IdWorker { |
|
|
else { |
|
|
else { |
|
|
sequence = 0L; |
|
|
sequence = 0L; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
logger.info(">>>>>workerId sequence"+sequence); |
|
|
//上次生成ID的时间截 |
|
|
//上次生成ID的时间截 |
|
|
lastTimestamp = timestamp; |
|
|
lastTimestamp = timestamp; |
|
|
|
|
|
|
|
|
|