All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.efeichong.uuid.IdGenerator Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
package com.efeichong.uuid;


/**
 * 基于Snowflake算法优化实现64位自增ID算法。
 *
 * @author lxk
 * @date 2020/11/10
 * @description 1. 如果发现当前时间少于上次生成id的时间(时间回拨),着计算回拨的时间差
 * 2. 如果时间差(offset)小于等于5ms,着等待 offset * 2 的时间再生成
 * 3. 如果offset大于5,则直接抛出异常
 */
public class IdGenerator {
    private static Sequence WORKER = new Sequence(0);

    public static long getId() {
        return WORKER.nextId();
    }

    public static String getIdStr() {
        return String.valueOf(WORKER.nextId());
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy