public class ConcurrencyTester extends Object implements Closeable
ps: //模拟1000个线程并发 ConcurrencyTester ct = new ConcurrencyTester(1000); ct.test(() -> { // 需要并发测试的业务代码 }); Console.log(ct.getInterval()); ct.close();
Constructor and Description |
---|
ConcurrencyTester(int threadSize)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
long |
getInterval()
获取执行时间
|
ConcurrencyTester |
reset()
重置测试器,重置包括:
清空worker
重置计时器
|
ConcurrencyTester |
test(Runnable runnable)
执行测试
执行测试后不会关闭线程池,可以调用 close() 释放线程池 |
public ConcurrencyTester(int threadSize)
threadSize
- 线程数public ConcurrencyTester test(Runnable runnable)
close()
释放线程池runnable
- 要测试的内容public ConcurrencyTester reset()
public long getInterval()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2024. All rights reserved.