雪花算法单列模式实例化对象

yun-zuoyi
jiajia 12 months ago
parent ebbb1b9f34
commit 33e1c1abaf

@ -32,6 +32,26 @@ public class SnowflakeIdMaker {
private long datacenterId;
private long sequence = 0L;
private volatile static SnowflakeIdMaker snowflakeIdMaker = null;
/**
*
* @return
*/
public static SnowflakeIdMaker getSingleton(){
if (snowflakeIdMaker == null){
synchronized (SnowflakeIdMaker.class){
if (snowflakeIdMaker == null) {
snowflakeIdMaker = new SnowflakeIdMaker();
}
}
}
return snowflakeIdMaker;
}
/**
* ,ID
*/
@ -42,6 +62,8 @@ public class SnowflakeIdMaker {
this.sequence = 0L;
}
/**
* ID
* @param workerId ID
@ -104,12 +126,12 @@ public class SnowflakeIdMaker {
private long lastTimestamp = -1L;
private long getWorkerId(){
return workerId;
public long getWorkerId(){
return this.workerId;
}
private long getDatacenterId(){
return datacenterId;
public long getDatacenterId(){
return this.datacenterId;
}
public synchronized long nextId() {

Loading…
Cancel
Save