Created
August 26, 2013 05:20
-
-
Save henryyan/6338305 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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