Class StrictlyClock

java.lang.Object
icu.congee.id.generator.lexical.StrictlyClock
All Implemented Interfaces:
Clock
Direct Known Subclasses:
MicrosecondEpochClock

public abstract class StrictlyClock extends Object implements Clock
一个并发的、严格递增的时钟实现

该实现保证生成的时间戳总是严格递增的,即使在多线程环境下也能保持正确性。 它使用AtomicLong来存储最后一次生成的时间戳,并通过CAS操作来确保线程安全。

Since:
2024-05-01
Version:
1.0
Author:
ixiongdi
  • Constructor Details

    • StrictlyClock

      public StrictlyClock()
  • Method Details

    • timestamp

      public long timestamp()
      Description copied from interface: Clock
      获取当前时间戳
      Specified by:
      timestamp in interface Clock
      Returns:
      当前时间戳
    • tick

      protected abstract long tick()
      获取当前的时间戳

      子类需要实现这个方法来提供基础的时间戳。这个时间戳不需要保证严格递增, 因为StrictlyClock会在此基础上确保最终返回的时间戳是严格递增的。

      Returns:
      当前的时间戳