mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
support back
This commit is contained in:
parent
6b6366e1ef
commit
8bcb1daf99
@ -24,6 +24,7 @@
|
|||||||
* 【crypto 】 AsymmetricAlgorithm去除EC(issue#887@Github)
|
* 【crypto 】 AsymmetricAlgorithm去除EC(issue#887@Github)
|
||||||
* 【cache 】 超时缓存使用的线程池大小默认为1(issue#890@Github)
|
* 【cache 】 超时缓存使用的线程池大小默认为1(issue#890@Github)
|
||||||
* 【poi 】 ExcelSaxReader支持handleCell方法
|
* 【poi 】 ExcelSaxReader支持handleCell方法
|
||||||
|
* 【core 】 Snowflake容忍2秒内的时间回拨(issue#I1IGDX@Gitee)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
||||||
|
@ -141,10 +141,16 @@ public class Snowflake implements Serializable {
|
|||||||
public synchronized long nextId() {
|
public synchronized long nextId() {
|
||||||
long timestamp = genTime();
|
long timestamp = genTime();
|
||||||
if (timestamp < lastTimestamp) {
|
if (timestamp < lastTimestamp) {
|
||||||
// 如果服务器时间有问题(时钟后退) 报错。
|
if(lastTimestamp - timestamp < 2000){
|
||||||
throw new IllegalStateException(StrUtil.format("Clock moved backwards. Refusing to generate id for {}ms", lastTimestamp - timestamp));
|
// 容忍2秒内的回拨,避免NTP校时造成的异常
|
||||||
|
timestamp = lastTimestamp;
|
||||||
|
} else{
|
||||||
|
// 如果服务器时间有问题(时钟后退) 报错。
|
||||||
|
throw new IllegalStateException(StrUtil.format("Clock moved backwards. Refusing to generate id for {}ms", lastTimestamp - timestamp));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (lastTimestamp == timestamp) {
|
|
||||||
|
if (timestamp == lastTimestamp) {
|
||||||
sequence = (sequence + 1) & sequenceMask;
|
sequence = (sequence + 1) & sequenceMask;
|
||||||
if (sequence == 0) {
|
if (sequence == 0) {
|
||||||
timestamp = tilNextMillis(lastTimestamp);
|
timestamp = tilNextMillis(lastTimestamp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user