多线程Callable使用invokeAll处理返回数据
在访问第三方接口时通过多线程实现,并且对返回数据进行处理。废话不多说,直接上源码。
@Test
public void testThread() throws Exception {
// 创建一个定长线程池,可控制线程最大并发数,超出的线程会在队列中等待。
ExecutorService service = Executors.newFixedThreadPool(5);
// 接收结果
ArrayList<Callable<List<Ehs>>> list = new ArrayList<Callable<List<Ehs>>>();
// 订单号
final List<String> OrderIdListNEW = new ArrayList<String>();
//测试专用
OrderIdListNEW.add("9973539124611");
OrderIdListNEW.a