Skip to content

Commit 058c029

Browse files
committed
리팩토링
1 parent 0cee0c3 commit 058c029

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

algorithm/src/main/java/io/github/gunkim/algorithm/identifier/SnowFlakeIdentifierGenerator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public SnowFlakeIdentifierGenerator(long epoch, long workerId, long datacenterId
4242
}
4343

4444
public synchronized SnowFlakeIdentifier nextId() {
45-
long timestamp = System.currentTimeMillis() - epoch;
45+
long timestamp = currentTimestamp();
4646

4747
if (timestamp < lastTimestamp) {
4848
throw new RuntimeException("시스템 시계가 이전 시간으로 되돌아갔습니다");
@@ -62,10 +62,14 @@ public synchronized SnowFlakeIdentifier nextId() {
6262
}
6363

6464
private long tilNextMillis(long lastTimestamp) {
65-
long timestamp = System.currentTimeMillis() - epoch;
65+
long timestamp = currentTimestamp();
6666
while (timestamp <= lastTimestamp) {
67-
timestamp = System.currentTimeMillis() - epoch;
67+
timestamp = currentTimestamp();
6868
}
6969
return timestamp;
7070
}
71+
72+
private long currentTimestamp() {
73+
return System.currentTimeMillis() - epoch;
74+
}
7175
}

0 commit comments

Comments
 (0)