记得上下班打卡 | git大法好,push需谨慎

Commit c94cce24 authored by 张国柄's avatar 张国柄

fix:ID GEN;

parent cb79b2a8
...@@ -2,13 +2,13 @@ package com.liquidnet.commons.lang.util; ...@@ -2,13 +2,13 @@ package com.liquidnet.commons.lang.util;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.util.Arrays;
import java.util.Enumeration; import java.util.Enumeration;
public class IDGenerator { public class IDGenerator {
private static final long twepoch = 1605456000000L; private static final long twepoch = 1624118400000L;
private static final long workerIdBits = 5L; // private static final long twepoch = 961421243000L;
private static final long dataCenterIdBits = 5L; private static final long workerIdBits = 2L;
private static final long dataCenterIdBits = 1L;
//// 最大支持机器节点数0~31,一共32个 //// 最大支持机器节点数0~31,一共32个
// 最大支持数据中心节点数0~31,一共32个 // 最大支持数据中心节点数0~31,一共32个
@SuppressWarnings({"PointlessBitwiseExpression", "FieldCanBeLocal"}) @SuppressWarnings({"PointlessBitwiseExpression", "FieldCanBeLocal"})
...@@ -40,7 +40,7 @@ public class IDGenerator { ...@@ -40,7 +40,7 @@ public class IDGenerator {
/* ---------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------- */
public static synchronized Long nextSnowId() { public static synchronized String nextSnowId() {
long timestamp = genTime(); long timestamp = genTime();
if (timestamp < lastTimestamp) { if (timestamp < lastTimestamp) {
if (lastTimestamp - timestamp < 2000) { if (lastTimestamp - timestamp < 2000) {
...@@ -63,7 +63,10 @@ public class IDGenerator { ...@@ -63,7 +63,10 @@ public class IDGenerator {
lastTimestamp = timestamp; lastTimestamp = timestamp;
return ((timestamp - twepoch) << timestampLeftShift) | (dataCenterId << dataCenterIdShift) | (workerId << workerIdShift) | sequence; long l = ((timestamp - twepoch) << timestampLeftShift) | (dataCenterId << dataCenterIdShift) | (workerId << workerIdShift) | sequence;
// return l;
return l + ("" + System.nanoTime()).substring(9);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment