0
是一個列表試圖一批項目清單到單個事務如下面從大宗交易
Lists.partition(new ArrayList()<>(customer),100).parallelStream().forEach(customers->{
UserTransaction userTransaction = new UserTransactionImp();
try {
userTransaction.begin();
for(String cus : customers){
//code to write to db
}
userTransaction.commit();
} catch (Exception exception) {
//collect the failed list and re partition them into smaller lists say 50
}
,但我不想失敗,所有的100只因爲幾個錯誤accounts.I上午識別失敗項目想收集失敗的項目進入一個更名單,並進一步劃分成小單子。我可以通過調用並行流做到這一點通常again.But我想知道是否有任何的設計模式來解決這個
'customer.removeIf(C - >/**一些條件** /);'與錯誤刪除所有的客戶。然後運行你的代碼。 –
要尋找的設計模式,如果任何 – pppavan
地方'裏面試試'for'環...... catch'塊。這樣你可以收集失敗的交易。 –