JDK8线程池/线程执行高负载方法

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

  public void xxMethod() {   
// 创建线程池   ExecutorService threadPool = Executors.newFixedThreadPool(list.size());   // 获取模板code及设备类型信息   for (Object object: list) {   String xxx = object.getXxx();   String yyy = object.getYyy();   threadPool.submit(new XxClass(xxx , yyy));   }

  }
/** * 线程内部类 */ class XxClass implements Runnable { private String xxx; private String yyy; public XxClass (String xxx, String yyy) { this.xxx= xxx; this.yyy= yyy; } @Override public void run() { xxMethod(xxx, yyy); }

   }

线程池大小根据业务需求调整

如需返回值可实现Callable接口

猜你喜欢

转载自www.cnblogs.com/huahuavip/p/9492533.html