Package me.ahoo.cosid.snowflake
Class SafeJavaScriptSnowflakeId
java.lang.Object
me.ahoo.cosid.snowflake.SafeJavaScriptSnowflakeId
Safe JavaScript Number ID.
Number.MAX_SAFE_INTEGER = 9007199254740991
Math.log2(Number.MAX_SAFE_INTEGER) = 53
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isSafeJavaScript
(long id) static MillisecondSnowflakeId
ofMillisecond
(int machineId) Max Sequence (9 bits) = ((1<<)*1000) = 512000 (TPS) Max Machine (3 bits) = 1<<3 = 8 Max Timestamp = 2199023255551 ms ~~ 69.7 yearsstatic MillisecondSnowflakeId
ofMillisecond
(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold) static SecondSnowflakeId
ofSecond
(int machineId) Max Sequence (19 bits) = (1<<19) = 524288 (TPS).static SecondSnowflakeId
ofSecond
(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold)
-
Field Details
-
JAVA_SCRIPT_MAX_SAFE_NUMBER_BIT
public static final int JAVA_SCRIPT_MAX_SAFE_NUMBER_BIT- See Also:
-
JAVA_SCRIPT_MAX_SAFE_NUMBER
public static final long JAVA_SCRIPT_MAX_SAFE_NUMBER- See Also:
-
-
Constructor Details
-
SafeJavaScriptSnowflakeId
public SafeJavaScriptSnowflakeId()
-
-
Method Details
-
isSafeJavaScript
public static boolean isSafeJavaScript(long id) -
ofMillisecond
public static MillisecondSnowflakeId ofMillisecond(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold) -
ofMillisecond
Max Sequence (9 bits) = ((1<<)*1000) = 512000 (TPS) Max Machine (3 bits) = 1<<3 = 8 Max Timestamp = 2199023255551 ms ~~ 69.7 years- Parameters:
machineId
- 服务实例编号- Returns:
- MillisecondSnowflakeId
-
ofSecond
public static SecondSnowflakeId ofSecond(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold) -
ofSecond
Max Sequence (19 bits) = (1<<19) = 524288 (TPS). Max Machine (3 bits) = 1<<3 = 8 Max Timestamp = 2147483647 s ~~ 68 years- Parameters:
machineId
- 服务实例编号- Returns:
- SecondSnowflakeId
-