Am trying to batch a list of items into single transaction like below
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
}
But i dont want to fail all the 100 just because few faulty accounts.I am thinking to collect the failed items into one more list and partition further into small list .I can do this normally by invoking parallel stream again.But i wanted to know if there is any design pattern to solve this
Aucun commentaire:
Enregistrer un commentaire