Skip to content

Commit dd71fac

Browse files
committed
used checkNodebounds
1 parent 5363b68 commit dd71fac

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/main/java/com/gb/didgen/service/SnowflakeIdGenerator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class SnowflakeIdGenerator implements IdGenerator {
2323
private final int generatingNodeId;
2424
private volatile long currentSequence;
2525
private final Object lock = new Object();
26-
private volatile long lastTimestamp = 0L;
26+
private volatile long lastTimestamp;
2727

2828
@PostConstruct
2929
public void checkNodeIdBounds() throws NodeIdOutOfBoundException {
@@ -33,7 +33,8 @@ public void checkNodeIdBounds() throws NodeIdOutOfBoundException {
3333
}
3434

3535
@Override
36-
public long generateId() throws ClockMovedBackException {
36+
public long generateId() throws ClockMovedBackException, NodeIdOutOfBoundException {
37+
checkNodeIdBounds();
3738
synchronized (lock) {
3839
long currentTimeStamp = getTimeStamp();
3940
if (currentTimeStamp < lastTimestamp) {

0 commit comments

Comments
 (0)