664 Star 2.9K Fork 853

柠檬夕桐 / sequence

 / 详情

对于某段代码出现wait的请教

Backlog
Opened this issue  
2021-02-01 09:48
 if (offset <= 5) {
                try {
                    wait(offset << 1);
                    timestamp = timeGen();
                    if (timestamp < lastTimestamp) {
                        throw new RuntimeException(String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", offset));
                    }
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            } else {
                throw new RuntimeException(String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", offset));
            }

这段代码为啥在offset 小于5的时候要去wait,请作者帮忙解答一下。

Comments (1)

ttjkst created任务
ttjkst set related repository to 沐浴夕桐/sequence
Expand operation logs

时间回拨了啊,等待然后再校验时间,没问题生成新的id

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
Java
1
https://gitee.com/yu120/sequence.git
git@gitee.com:yu120/sequence.git
yu120
sequence
sequence

Search