@Transactional
public Integer insertBatch(List<User> list) {
int cnt = list.size();
int threadCnt = cnt / 500;
if(cnt%500 > 0) {
threadCnt++;
}
final CountDownLatch cdl= new CountDownLatch(threadCnt);
List<User> threadList = null;
for (int i = 0; i < threadCnt; i++) {
threadList = i == threadCnt-1 ? list.subList(i * 500, list.size()-1) : list.subList(i*500, (i+1)*500);
new Thread(new UserInsertThread(cdl, threadList)).start();
}
try {
cdl.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return 0;
}原文:http://blog.51cto.com/xinzhilian/2089523