public synchronized long nextId() {
        long timestamp = System.nanoTime();
        if (this.lastTimestamp == timestamp) {
            this.sequence = this.sequence + 1 & sequenceMask;
            if (this.sequence == 0) {
                timestamp = this.tillNextMillis(this.lastTimestamp);
            }
        } else {
            this.sequence = 0;
        }
        this.lastTimestamp = timestamp;
        return Math.abs(timestamp - twepoch << timestampLeftShift | this.workerId << workerIdShift | this.sequence);
    }
reference :https://github.com/twitter/snowflake/blob/master/src/main/scala/com/twitter/service/snowflake/IdWorker.scala
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/common/utils/IdWorker.java