Class CountdownMutilThreadRunner

java.lang.Object
tech.riemann.etp.thread.MutilThreadRunner
tech.riemann.etp.thread.CountdownMutilThreadRunner

public class CountdownMutilThreadRunner extends MutilThreadRunner
Author:
Kerbores(kerbores@riemann.tech)
  • Constructor Details

    • CountdownMutilThreadRunner

      public CountdownMutilThreadRunner()
  • Method Details

    • run

      public void run(JobRunner jobRunner, int threads) throws InterruptedException
      使用指定数量的线程并行执行给定的JobRunner任务. 本方法通过创建一个计数器为threads的CountDownLatch对象,来同步等待所有线程完成执行。 对于每一个线程,将通过RunThread的builder方法配置其索引、总线程数、JobRunner实例和CountDownLatch对象, 然后构建并启动线程。所有线程启动后,主线程将通过调用CountDownLatch的await方法, 阻塞等待直到所有线程完成执行,从而确保整体任务的同步性。
      Overrides:
      run in class MutilThreadRunner
      Parameters:
      jobRunner - 要执行的JobRunner实例.
      threads - 线程池中线程的数量.
      Throws:
      InterruptedException - 如果在等待过程中被中断.