ways to improve the performance of this scenario

前端 未结 6 1039
闹比i
闹比i 2021-01-23 05:45

I have a map with huge amount of data being populated (around 300,000 records in approx)

and iterating it as below ,

    for (Map.Entry&         


        
6条回答
  •  日久生厌
    2021-01-23 06:10

    You should use jdbc batch update feature.

    While iterating over map you add batch to your prepared statement. When you has added (say) 2000 records, you call stmt.batchUpdate() which will update 2000 diferent records in fast way.

    Some example you can see here:

    http://www.mkyong.com/jdbc/jdbc-preparedstatement-example-batch-update/

    Second thing - If you can, make transaction commit after each batchUpdate. Transaction for 300k records may be to much for your database configuration. Splitting this update into many transactions will have better performance - but only if you can not to have transaction on all records.

提交回复
热议问题