Class ThrowException
java.lang.Object
cloud.opencode.base.id.snowflake.ThrowException
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface ClockBackwardStrategy
ClockBackwardStrategy.Custom -
Method Summary
Modifier and TypeMethodDescriptionstatic ThrowExceptionGets the singleton instance 获取单例实例longhandle(long lastTimestamp, long currentTimestamp) Handles clock backward movement 处理时钟回拨toString()
-
Method Details
-
getInstance
Gets the singleton instance 获取单例实例- Returns:
- singleton instance | 单例实例
-
handle
public long handle(long lastTimestamp, long currentTimestamp) Description copied from interface:ClockBackwardStrategyHandles clock backward movement 处理时钟回拨- Specified by:
handlein interfaceClockBackwardStrategy- Parameters:
lastTimestamp- the last timestamp used | 上次使用的时间戳currentTimestamp- the current (backward) timestamp | 当前(回拨的)时间戳- Returns:
- the timestamp to use | 要使用的时间戳
-
toString
-