IdGenerator icon indicating copy to clipboard operation
IdGenerator copied to clipboard

疑问

Open MuJianxuan opened this issue 8 months ago • 0 comments

@Slf4j public class YitterMain {

static {
    // 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId:
    IdGeneratorOptions options = new IdGeneratorOptions((short) 1221865536);
     options.WorkerIdBitLength = 16; // 默认值6,限定 WorkerId 最大值为2^6-1,即默认最多支持64个节点。
     options.SeqBitLength = 6; // 默认值6,限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
     options.BaseTime = SystemClock.now(); // 如果要兼容老系统的雪花算法,此处应设置为老系统的BaseTime。
    // ...... 其它参数参考 IdGeneratorOptions 定义。

    // 保存参数(务必调用,否则参数设置不生效):
    YitIdHelper.setIdGenerator(options);

    // 以上过程只需全局一次,且应在生成ID之前完成。
}

public static void main(String[] args) {

    long nextId = YitIdHelper.nextId();
    log.info("{}",nextId);

    // 2的16次方是多少
    log.info("{}",Math.pow(2,16));

}

} 为什么我设置的options.WorkerIdBitLength = 16;,完的workerID还可以大于65536

MuJianxuan avatar Apr 21 '25 07:04 MuJianxuan