Class FlexIDKeyGenerator

java.lang.Object
icu.congee.id.generator.flexid.FlexIDKeyGenerator
All Implemented Interfaces:
IdGenerator

public class FlexIDKeyGenerator extends Object implements IdGenerator
独创的 FlexID 算法(简单、好用):

特点: 1、保证 id 生成的顺序为时间顺序,越往后生成的 ID 值越大; 2、运行时,单台机器并发量在每秒钟 10w 以内; 3、运行时,无视时间回拨; 4、最大支持 99 台机器; 5、够用大概 300 年左右的时间;

缺点: 1、每台机器允许最大的并发量为 10w/s。 2、出现时间回拨,重启机器时,在时间回拨未恢复的情况下,可能出现 id 重复。

ID组成:时间(7+)| 毫秒内的时间自增 (00~99:2)| 机器ID(00 ~ 99:2)| 随机数(00~99:2)用于分库分表时,通过 id 取模,保证分布均衡。

  • Constructor Details

    • FlexIDKeyGenerator

      public FlexIDKeyGenerator()
    • FlexIDKeyGenerator

      public FlexIDKeyGenerator(long workId)
  • Method Details

    • generate

      public Long generate()
      Description copied from interface: IdGenerator
      生成一个唯一标识符。 每个实现类都应该根据其特定的生成策略来实现此方法。
      Specified by:
      generate in interface IdGenerator
      Returns:
      生成的唯一标识符,具体类型由实现类决定
    • idType

      public IdType idType()
      Description copied from interface: IdGenerator
      获取当前生成器的标识符类型

      此方法用于标识生成器使用的具体ID生成策略。每个实现类都应该 返回一个对应其生成策略的IdType枚举值。

      Specified by:
      idType in interface IdGenerator
      Returns:
      当前生成器的标识符类型