public class SnowflakeIdGenerator extends Object
| Constructor and Description |
|---|
SnowflakeIdGenerator(long workerId,
long datacenterId)
构造函数
|
| Modifier and Type | Method and Description |
|---|---|
long |
nextId()
获得下一个ID (该方法是线程安全的)
|
protected void |
throwClockBackwardsEx(long lastTimestamp,
long timestamp) |
protected long |
tilNextMillis(long lastTimestamp)
阻塞到下一个毫秒,直到获得新的时间戳
|
protected long |
timeGen()
返回以毫秒为单位的当前时间
|
public SnowflakeIdGenerator(long workerId,
long datacenterId)
workerId - 工作ID (0~31)datacenterId - 数据中心ID (0~31)public long nextId()
protected long tilNextMillis(long lastTimestamp)
lastTimestamp - 上次生成ID的时间截protected long timeGen()
protected void throwClockBackwardsEx(long lastTimestamp,
long timestamp)
Copyright © 2026. All rights reserved.