Class DeadlineContext
java.lang.Object
cloud.opencode.base.parallel.deadline.DeadlineContext
Deadline Context — ScopedValue-based deadline propagation for virtual threads
截止时间上下文 — 基于 ScopedValue 的虚拟线程截止时间传播
Allows binding a deadline to the current virtual thread scope so that all operations within that scope can check the deadline.
允许将截止时间绑定到当前虚拟线程作用域,使该作用域内的所有操作可以检查截止时间。
Example | 示例:
DeadlineContext.withTimeout(Duration.ofSeconds(5), () -> {
// All operations in this scope can check the deadline
Optional<Duration> remaining = DeadlineContext.remaining();
});
Features | 主要功能:
- ScopedValue-based deadline propagation - 基于ScopedValue的截止时间传播
- Timeout and deadline binding - 超时和截止时间绑定
- Remaining time checking - 剩余时间检查
- Virtual thread scope inheritance - 虚拟线程作用域继承
Security | 安全性:
- Thread-safe: Yes (ScopedValue is inherently thread-safe) - 线程安全: 是(ScopedValue天然线程安全)
- Since:
- JDK 25, opencode-base-parallel V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncurrent()static booleanisBound()static booleanstatic voidwithDeadline(Instant deadline, Runnable action) static <T> TwithDeadline(Instant deadline, Callable<T> action) static voidwithTimeout(Duration timeout, Runnable action) static <T> TwithTimeout(Duration timeout, Callable<T> action)
-
Method Details
-
withDeadline
-
withDeadline
-
withTimeout
-
withTimeout
-
current
-
remaining
-
isBound
public static boolean isBound() -
isExpired
public static boolean isExpired()
-