0

Let's say there is a millions of records in DB. I need to do some transactions based on each of them as quickly as possible. I'm using Java EE 6.

query.setMaxResults(1000);
List<MyEntity> list = query.getResultList();

while(list != null && !list.isEmpty()){
    for(int i = 0; i < list.size(); i++) {
        MyEntity entity = list.get(i);
        SomeTransactionMethod(entity);
    }

    list = query.getResultList();
}

SomeTransaction method performs select on 6 tables and inserts into 1 table. Should I annotate SomeTransaction with @Asynchronous? If so, how could I wait for all of them to finish so that I can work on next 1000 records?

2
  • 1
    I hate PL/SQL as much as the next guy but this may be one of those rare cases where it might be better...
    – nablex
    Sep 9, 2014 at 7:14
  • 2
    If you need to update millions of rows, sending them across the wire to your Java program and back again is definitely not the way to go. Sep 9, 2014 at 7:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.