public synchronized long nextId() throws InvalidSystemClock {
        long timestamp = timeGen();
        long curSequence = 0L;

        final long prevTimestamp = lastTimestamp.get();

        if (timestamp < prevTimestamp) {
            exceptionsCounter.inc();
            LOGGER.error(
                    "clock is moving backwards. Rejecting requests until {}",
                    prevTimestamp);
            throw new InvalidSystemClock(
                    String.format(
                            "Clock moved backwards. Refusing to generate id for %d milliseconds",
                            (prevTimestamp - timestamp)));
        }

        if (prevTimestamp == timestamp) {
            curSequence = sequence.incrementAndGet() & SEQUENCE_MASK;
            if (curSequence == 0) {
                timestamp = tilNextMillis(prevTimestamp);
            }
        } else {
            curSequence = 0L;
            sequence.set(0L);
        }

        lastTimestamp.set(timestamp);
        final long id = ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT)
                | (datacenterId << DATACENTER_ID_SHIFT)
                | (workerId << WORKER_ID_SHIFT) | curSequence;

        LOGGER.trace(
                "prevTimestamp = {}, timestamp = {}, sequence = {}, id = {}",
                prevTimestamp, timestamp, sequence, id);

        return id;
    }
public synchronized long nextId ( ) throws InvalidSystemClock { long timestamp = timeGen ( ) ; long curSequence = 0L ; final long prevTimestamp = lastTimestamp . get ( ) ; if ( timestamp < prevTimestamp ) { exceptionsCounter . inc ( ) ; LOGGER . error ( "clock is moving backwards. Rejecting requests until {}" , prevTimestamp ) ; throw new InvalidSystemClock ( String . format ( "Clock moved backwards. Refusing to generate id for %d milliseconds" , ( prevTimestamp - timestamp ) ) ) ; } if ( prevTimestamp == timestamp ) { curSequence = sequence . incrementAndGet ( ) & SEQUENCE_MASK ; if ( curSequence == 0 ) { timestamp = tilNextMillis ( prevTimestamp ) ; } } else { curSequence = 0L ; sequence . set ( 0L ) ; } lastTimestamp . set ( timestamp ) ; final long id = ( ( timestamp - TWEPOCH ) << TIMESTAMP_LEFT_SHIFT ) | ( datacenterId << DATACENTER_ID_SHIFT ) | ( workerId << WORKER_ID_SHIFT ) | curSequence ; LOGGER . trace ( "prevTimestamp = {}, timestamp = {}, sequence = {}, id = {}" , prevTimestamp , timestamp , sequence , id ) ; return id ; }
Get the next ID

@return Next ID
@throws InvalidSystemClock
When the clock is moving backward