public final class DefaultKeyGenerator extends Object implements KeyGenerator
Use snowflake algorithm. Length is 64 bit.
1bit sign bit. 41bits timestamp offset from 2016.11.01(ShardingSphere distributed primary key published data) to now. 10bits worker process id. 12bits auto increment offset in one mills
Call @DefaultKeyGenerator.setWorkerId to set worker id, default value is 0.
Call @DefaultKeyGenerator.setMaxTolerateTimeDifferenceMilliseconds to set max tolerate time difference milliseconds, default value is 0.
| 限定符和类型 | 字段和说明 |
|---|---|
static long |
EPOCH |
| 构造器和说明 |
|---|
DefaultKeyGenerator() |
| 限定符和类型 | 方法和说明 |
|---|---|
Number |
generateKey()
Generate key.
|
static void |
setMaxTolerateTimeDifferenceMilliseconds(int maxTolerateTimeDifferenceMilliseconds)
Set max tolerate time difference milliseconds.
|
static void |
setWorkerId(long workerId)
Set work process id.
|
public static void setWorkerId(long workerId)
workerId - work process idpublic static void setMaxTolerateTimeDifferenceMilliseconds(int maxTolerateTimeDifferenceMilliseconds)
maxTolerateTimeDifferenceMilliseconds - max tolerate time difference millisecondspublic Number generateKey()
generateKey 在接口中 KeyGeneratorLong.Copyright © 2018. All rights reserved.