Class ThrowException

java.lang.Object
cloud.opencode.base.id.snowflake.ThrowException
All Implemented Interfaces:
ClockBackwardStrategy

public final class ThrowException extends Object implements ClockBackwardStrategy
Throw Exception Strategy for Clock Backward Handling 时钟回拨抛异常策略

Immediately throws an exception when clock backward is detected. This is the strictest strategy, suitable for scenarios that cannot tolerate any clock inconsistency.

检测到时钟回拨时立即抛出异常。这是最严格的策略, 适用于不能容忍任何时钟不一致的场景。

Features | 主要功能:

  • Singleton instance - 单例实例
  • Fail-fast behavior - 快速失败行为
  • Zero tolerance for clock backward - 对时钟回拨零容忍

Usage Examples | 使用示例:

ClockBackwardStrategy strategy = ThrowException.getInstance();

SnowflakeGenerator gen = SnowflakeBuilder.create()
    .clockBackwardStrategy(ThrowException.getInstance())
    .build();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
Since:
JDK 25, opencode-base-id V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • getInstance

      public static ThrowException getInstance()
      Gets the singleton instance 获取单例实例
      Returns:
      singleton instance | 单例实例
    • handle

      public long handle(long lastTimestamp, long currentTimestamp)
      Description copied from interface: ClockBackwardStrategy
      Handles clock backward movement 处理时钟回拨
      Specified by:
      handle in interface ClockBackwardStrategy
      Parameters:
      lastTimestamp - the last timestamp used | 上次使用的时间戳
      currentTimestamp - the current (backward) timestamp | 当前(回拨的)时间戳
      Returns:
      the timestamp to use | 要使用的时间戳
    • toString

      public String toString()
      Overrides:
      toString in class Object