Class ConcurrencyTester

java.lang.Object
org.miaixz.bus.core.lang.thread.ConcurrencyTester
All Implemented Interfaces:
Closeable, AutoCloseable

public class ConcurrencyTester extends Object implements Closeable
高并发测试工具类
 ps:
 //模拟1000个线程并发
 ConcurrencyTester ct = new ConcurrencyTester(1000);
 ct.test(() -> {
      // 需要并发测试的业务代码
 });

 Console.logger(ct.getInterval());
 ct.close();
 
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • ConcurrencyTester

      public ConcurrencyTester(int threadSize)
      构造
      Parameters:
      threadSize - 线程数
  • Method Details

    • test

      public ConcurrencyTester test(Runnable runnable)
      执行测试 执行测试后不会关闭线程池,可以调用close()释放线程池
      Parameters:
      runnable - 要测试的内容
      Returns:
      this
    • reset

      public ConcurrencyTester reset()
      重置测试器,重置包括:
      • 清空worker
      • 重置计时器
      Returns:
      this
    • getInterval

      public long getInterval()
      获取执行时间
      Returns:
      执行时间,单位毫秒
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException