Class ThreadSafetyChecker
java.lang.Object
cloud.opencode.base.test.concurrent.ThreadSafetyChecker
Thread Safety Checker
线程安全检查器
Utility for checking thread safety of objects.
用于检查对象线程安全性的工具。
Features | 主要功能:
- Thread safety checking utilities - 线程安全检查工具
- Counter and operation safety checks - 计数器和操作安全检查
Usage Examples | 使用示例:
CheckResult result = ThreadSafetyChecker.checkCounter(
() -> counter.incrementAndGet(),
counter::get, 10, 1000);
assertTrue(result.passed());
- Since:
- JDK 25, opencode-base-test V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordCheck result 检查结果 -
Method Summary
Modifier and TypeMethodDescriptioncheckCounter(Runnable incrementTask, Supplier<Integer> getCountTask, int threads, int incrementsPerThread) Check if a counter is thread-safe 检查计数器是否线程安全static booleanisThreadSafe(Runnable operation, int threads, int iterations) Check if object operations are thread-safe 检查对象操作是否线程安全
-
Method Details
-
checkCounter
public static ThreadSafetyChecker.CheckResult checkCounter(Runnable incrementTask, Supplier<Integer> getCountTask, int threads, int incrementsPerThread) Check if a counter is thread-safe 检查计数器是否线程安全- Parameters:
incrementTask- the increment task | 递增任务getCountTask- the get count task | 获取计数任务threads- the number of threads | 线程数incrementsPerThread- increments per thread | 每线程递增次数- Returns:
- the result | 结果
-
isThreadSafe
Check if object operations are thread-safe 检查对象操作是否线程安全- Parameters:
operation- the operation | 操作threads- the number of threads | 线程数iterations- iterations per thread | 每线程迭代次数- Returns:
- true if thread-safe | 如果线程安全返回true
-