记得上下班打卡 | git大法好,push需谨慎
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
liquidnet-bus-v1
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
董敬伟
liquidnet-bus-v1
Commits
c94cce24
Commit
c94cce24
authored
Jun 19, 2021
by
张国柄
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:ID GEN;
parent
cb79b2a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
IDGenerator.java
...ain/java/com/liquidnet/commons/lang/util/IDGenerator.java
+9
-6
No files found.
liquidnet-bus-common/liquidnet-common-base/src/main/java/com/liquidnet/commons/lang/util/IDGenerator.java
View file @
c94cce24
...
@@ -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
Lo
ng
nextSnowId
()
{
public
static
synchronized
Stri
ng
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
);
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment