Interface ClockBackwardsSynchronizer

All Known Implementing Classes:
DefaultClockBackwardsSynchronizer

@ThreadSafe public interface ClockBackwardsSynchronizer
Synchronizer for handling clock backwards issues in Snowflake ID generation.

When system clock moves backwards, this synchronizer waits until the clock catches up to ensure unique IDs.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Default synchronizer instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    getBackwardsTimeStamp(long lastTimestamp)
    Calculates how far backwards the clock has moved.
    void
    sync(long lastTimestamp)
    Synchronizes clock by waiting until current time exceeds lastTimestamp.
    void
    syncUninterruptibly(long lastTimestamp)
    Synchronizes clock without throwing InterruptedException.
  • Field Details

  • Method Details

    • sync

      void sync(long lastTimestamp) throws InterruptedException, ClockTooManyBackwardsException
      Synchronizes clock by waiting until current time exceeds lastTimestamp.
      Parameters:
      lastTimestamp - the last timestamp that was generated
      Throws:
      InterruptedException - if thread is interrupted while waiting
      ClockTooManyBackwardsException - if clock backwards exceeds threshold
    • syncUninterruptibly

      void syncUninterruptibly(long lastTimestamp) throws ClockTooManyBackwardsException
      Synchronizes clock without throwing InterruptedException.
      Parameters:
      lastTimestamp - the last timestamp that was generated
      Throws:
      ClockTooManyBackwardsException - if clock backwards exceeds threshold
    • getBackwardsTimeStamp

      static long getBackwardsTimeStamp(long lastTimestamp)
      Calculates how far backwards the clock has moved.
      Parameters:
      lastTimestamp - the last timestamp
      Returns:
      the backwards duration in milliseconds