Class SafeJavaScriptSnowflakeId

java.lang.Object
me.ahoo.cosid.snowflake.SafeJavaScriptSnowflakeId

public final class SafeJavaScriptSnowflakeId extends Object
Safe JavaScript Number ID. Number.MAX_SAFE_INTEGER = 9007199254740991 Math.log2(Number.MAX_SAFE_INTEGER) = 53
  • 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

      public 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 years
      Parameters:
      machineId - 服务实例编号
      Returns:
      MillisecondSnowflakeId
    • ofSecond

      public static SecondSnowflakeId ofSecond(long epoch, int timestampBit, int machineBit, int sequenceBit, int machineId, long sequenceResetThreshold)
    • ofSecond

      public static SecondSnowflakeId ofSecond(int machineId)
      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