int nums = 5000;
int count = pubBookService.getBookExportCount(params);
int thrednum = (count % nums == 0) ? (count / nums) : (count / nums + 1);
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
ExecutorService service = Executors.newFixedThreadPool(thrednum);
BlockingQueue<Future<List<Map<String, Object>>>> queue = new LinkedBlockingQueue<Future<List<Map<String, Object>>>>();
for (int i = 0; i < thrednum; i++) {
Future<List<Map<String, Object>>> future = service.submit(read2List(i, nums, params));
queue.add(future);
}
int queueSize = queue.size();
for (int i = 0; i < queueSize; i++) {
List<Map<String, Object>> list = queue.take().get();
data.addAll(list);
}
service.shutdown();
private Callable<List<Map<String, Object>>> read2List(final int i, final int nums, final Map<String, Object> params) {
Callable<List<Map<String, Object>>> callable = new Callable<List<Map<String, Object>>>() {
public List<Map<String, Object>> call() throws Exception {
int startIndex = i * nums;
int maxIndex = startIndex + nums;
Map<String, Object> p = new HashMap<String, Object>();
p.putAll(params);
p.put("startIndex", startIndex);
p.put("maxIndex", maxIndex);
List<Map<String, Object>> list = pubBookService.getBookListExport(p);
return list;
}
};
return callable;
}