Skip to content

Instantly share code, notes, and snippets.

@henryyan
Created August 26, 2013 05:20
Show Gist options
  • Save henryyan/6338305 to your computer and use it in GitHub Desktop.
Save henryyan/6338305 to your computer and use it in GitHub Desktop.
public class AutoClaimService {
private int completeThreads = 0;
List<List<Bill>> splitBills;
public void doClaim() {
List<Bill> bills = // 用hibernate读取集合
splitBills = splitBills(bills, 10); // 每组十个
for (int i = 0; i < splitedBillList.size(); i++) {
AutoClaimThread claimThread = new AutoClaimThread();
Thread thread = new Thread(claimThread);
thread.start();
}
}
// 当所有线程都结束时统一保存实体
while (completeThreads == splitBills.size()) {
for (MedicalBill medicalBill : bills) {
System.out.println("id=" + medicalBill.getId() + ", status=" + medicalBill.getStatus() + ", close_status=" + medicalBill.getClosureStatus());
medicalBillManager.saveEntity(medicalBill);
}
break;
}
class ClaimThread implements Runnable {
List<Bill> innerBills;
public void run() {
for (Bill bill: innerBills) {
// do something
}
completeThreads++; // 线程完成计数器
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment