public class ConcurrencyTester extends Object implements Closeable
ps:
//模拟1000个线程并发
ConcurrencyTester ct = new ConcurrencyTester(1000);
ct.test(() -> {
// 需要并发测试的业务代码
});
Console.log(ct.getInterval());
ct.close();
| 构造器和说明 |
|---|
ConcurrencyTester(int threadSize)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
close() |
long |
getInterval()
获取执行时间
|
ConcurrencyTester |
reset()
重置测试器,重置包括:
清空worker
重置计时器
|
ConcurrencyTester |
test(Runnable runnable)
执行测试
执行测试后不会关闭线程池,可以调用 close()释放线程池 |
public ConcurrencyTester test(Runnable runnable)
close()释放线程池runnable - 要测试的内容public ConcurrencyTester reset()
public long getInterval()
public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionCopyright © 2022. All rights reserved.