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&
I'll try to summarize all good points mentioned above.
Your options are,
Another good option is use bulk update but again bulk update comes with cost of more lock time at database end. so use it wisely as threads will be waiting till one thread finishes with updating as update will take exclusive lock i.e. no sharing possible.
Try threading in along with async jobs (specially for mails) try to use different server/process for mail handling and send mail requests to mail server asynchronously which is quite fast as your mail generation task is handled by other process (In real life mail exchange can accept some delay thus your slow mail server is allowed but application server is not.)
If possible move your complete Db update logic in stored procedure on DB server which will save your lot of time (Rule of Thumb : Always let A handle tasks for which A is designed/optimized i.e. DB are designed for faster DB operations than pgming languages.)
Couldn't give you answer specific to your need but I hope this was helpful in terms of improving it :)