Class ConcurrentTester
java.lang.Object
cloud.opencode.base.test.concurrent.ConcurrentTester
Concurrent Tester
并发测试器
Utility for testing concurrent behavior.
用于测试并发行为的工具。
Features | 主要功能:
- Concurrent execution testing - 并发执行测试
- Thread safety verification - 线程安全验证
Usage Examples | 使用示例:
ConcurrentTester.ConcurrentResult result =
ConcurrentTester.runConcurrently(() -> counter.incrementAndGet(), 10, 1000);
assertTrue(result.allSucceeded());
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- 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 recordConcurrent test result 并发测试结果 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertThreadSafe(Runnable task, int threads, int iterations) Assert task is thread-safe 断言任务是线程安全的runConcurrently(Runnable task, int threads, int iterations) Run task concurrently 并发运行任务runConcurrently(Consumer<Integer> task, int threads) Run task concurrently with index 带索引并发运行任务
-
Method Details
-
runConcurrently
public static ConcurrentTester.ConcurrentResult runConcurrently(Runnable task, int threads, int iterations) Run task concurrently 并发运行任务- Parameters:
task- the task | 任务threads- the number of threads | 线程数iterations- iterations per thread | 每线程迭代次数- Returns:
- the result | 结果
-
runConcurrently
public static ConcurrentTester.ConcurrentResult runConcurrently(Consumer<Integer> task, int threads) Run task concurrently with index 带索引并发运行任务- Parameters:
task- the task with thread index | 带线程索引的任务threads- the number of threads | 线程数- Returns:
- the result | 结果
-
assertThreadSafe
Assert task is thread-safe 断言任务是线程安全的- Parameters:
task- the task | 任务threads- the number of threads | 线程数iterations- iterations per thread | 每线程迭代次数
-