How to increase the performance of a loop which runs for every 'n' minutes.
Posted
by GustlyWind
on Stack Overflow
See other posts from Stack Overflow
or by GustlyWind
Published on 2010-06-07T13:23:24Z
Indexed on
2010/06/07
14:42 UTC
Read the original article
Hit count: 306
java
|Performance
Hi Giving small background to my requirement and what i had accomplished so far: There are 18 Scheduler tasks run at regular intervals (least being 30 mins) takes input of nearly 5000 eligible employees run into a static method for iteration and generates a mail content for that employee and mails. An average task takes about 9 min multiplied by 18 will be roughly 162 mins meanwhile there would be next tasks which will be in queue (I assume). So my plan is something like the below loop
try {
// Handle Arraylist of alerts eligible employees
Iterator employee = empIDs.iterator();
while (employee.hasNext()) {
ScheduledImplementation.getInstance().sendAlertInfoToEmpForGivenAlertType((Long)employee.next(), configType,schedType);
}
} catch (Exception vEx)
{
_log.error("Exception Caught During sending " + configType + " messages:" + configType, vEx);
}
Since I know how many employees would come to my method I will divide the while loop into two and perform simultaneous operations on two or three employees at a time. Is this possible. Or is there any other ways I can improve the performance. Some of the things I had implemented so far
1.Wherever possible made methods static and variables too
Didn't bother to catch exceptions and send back because these are background tasks. (And I assume this improves performance)
Get the DB values in one query instead of multiple hits.
If am successful in optimizing the while
loop I think i can save couple of mins.
Thanks
© Stack Overflow or respective owner