使用场景:需要同时创建多个线程去访问某一接口,并将返回数据进行组装
1. 创建ThreadPoolExecutor,切记创建在类的方法之外,这样就不会调用一次方法,创建一个ThreadPoolExecutor
private final static ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 30, 2000, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<Runnable>(100));
具体参数含义、原理、设置自行百度
2. 创建要执行任务的线程类
public class ExcuteTask implements Callable<BizResult<List<BudgetDTO>>> {
private BudgetForm form;
private BudgetService budgetService;
public ExcuteTask(BudgetForm form, BudgetService budgetService) {
this.form = form;
this.budgetService = budgetService;
}
@Override
public BizResult<List<Bu