mysql中in 大量数据 分组查询
Integer size = 200;
Integer total = orders.size();
Integer pages = total % size == 0 ? total / size : total / size + 1;
//线程池
ExecutorService service = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
List<InOrderIds> callables = new ArrayList<>();
for (int i = 0; i < pages; i++) {
Integer toIndex = (i + 1) * size > total ? total : (i + 1) * size;
callables.add(new InOrderIds(orderIds.subList(i * size, toIndex), i));
}
List<Future<List<Order>>> futures = service.invokeAll(callables);
List<Order> finalRes = new ArrayList<Order>(total);
futures.forEach((f) -> {
try {
System.out.println(finalRes.addAll(f.get()));
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
});
service.shutDown();//释放资源