|
|
|
@@ -1,6 +1,8 @@ |
|
|
|
package com.iformall.common; |
|
|
|
|
|
|
|
import com.iformall.utils.IPUtil; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.lang.management.ManagementFactory; |
|
|
|
import java.net.UnknownHostException; |
|
|
|
@@ -16,6 +18,7 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
|
|
|
|
public class IdWorker { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(IdWorker.class); |
|
|
|
// ==============================Fields=========================================== |
|
|
|
/** 开始时间截 (2015-01-01) */ |
|
|
|
private final long twepoch = 1489111610226L; |
|
|
|
@@ -60,16 +63,19 @@ public class IdWorker { |
|
|
|
private long lastTimestamp = -1L; |
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////// |
|
|
|
|
|
|
|
private static class IdGenHolder { |
|
|
|
private static final IdWorker instance = new IdWorker(); |
|
|
|
} |
|
|
|
|
|
|
|
public static IdWorker get(){ |
|
|
|
return IdGenHolder.instance; |
|
|
|
private static IdWorker instance = null; |
|
|
|
public static IdWorker get() { |
|
|
|
if(instance == null) { |
|
|
|
synchronized (IdWorker.class){ |
|
|
|
if(instance==null){ |
|
|
|
instance = new IdWorker(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return instance; |
|
|
|
} |
|
|
|
|
|
|
|
public IdWorker() { |
|
|
|
private IdWorker() { |
|
|
|
String ipAddr = ""; |
|
|
|
try { |
|
|
|
ipAddr = IPUtil.getLocalHostLANAddress().getHostAddress(); |
|
|
|
|