Skip to content

Commit

Permalink
发号器序列起始范围是否随机也可配置。
Browse files Browse the repository at this point in the history
  • Loading branch information
InsideZhou committed Oct 24, 2019
1 parent 975dcc1 commit 8acfbfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public JdbcIdGenerator(Metadata metadata, IdGeneratorWorkerTable workerTable, In
properties.getWorkerIdBits(),
properties.getLowPaddingBits(),
properties.getEpoch(),
new Random(),
properties.isRandomSequenceStart() ? new Random() : null,
properties.getSequenceStartRange(),
properties.getTickAccuracy()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ public static class Properties {
private int workerIdBits = 12;
private int lowPaddingBits = 2;
private int sequenceStartRange = 1000;
private boolean randomSequenceStart = true;

/**
* 发号器的时间精度/步长,单位:毫秒。如果值为1000,则发号器每滴答(发生变化的最小时间单位)一次,时间实际过去了1秒。
*/
private int tickAccuracy = 1000;

/**
* Thu Feb 01 2018 00:00:00 GMT, seconds
*/
private long epoch = 1517414400L;

public int getTickAccuracy() {
return tickAccuracy;
}
Expand All @@ -92,10 +98,13 @@ public void setTickAccuracy(int tickAccuracy) {
this.tickAccuracy = tickAccuracy;
}

/**
* Thu Feb 01 2018 00:00:00 GMT, seconds
*/
private long epoch = 1517414400L;
public boolean isRandomSequenceStart() {
return randomSequenceStart;
}

public void setRandomSequenceStart(boolean randomSequenceStart) {
this.randomSequenceStart = randomSequenceStart;
}

public int getSequenceStartRange() {
return sequenceStartRange;
Expand Down

0 comments on commit 8acfbfc

Please sign in to comment.