I developed a program which after every two minutes call db to check new tasks
public static void main(String[] args) {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleWithFixedDelay(new ESMSCampaignTask(), 0, 2, TimeUnit.MINUTES);
}
Now following code check from DB and execute threads
public void run() {
ExecutorService execService = Executors.newFixedThreadPool(5);
List<ScheduledCampaigns> scheduledCampaignsList = campaignsService.getScheduledCampaigns();
for (ScheduledCampaigns campaign : scheduledCampaignsList) {
String cmpName = "SCH_CAMPAIGNS_" + campaign.getCampaign_id();
execService.execute(new Runnable() {
public void run() {
smppService.submitShortMessage(campaign);
}
});
}//EO For Loop
}//EO Run
The solution i am looking for is that how i can get status of completion of above threads so that i update DB accordingly?
I tried to execService.awaitTermination(500, TimeUnit.SECONDS);
But i would not be able to start new threads until existing threads finish their task.
So solution should provide such functionality that i could be able to start new threads after every two minutes without waiting for existing threads completions and meanwhile i keep on getting status of threads completion so i update database accordingly.
Regards,
If you use
ExcecutorService.submit()rather thanexecute, you can get aFutureobject.Store this in a vector, and you can then loop through the items in this vector to check on their completion state.;
Sorry this is untested, but hope the idea is useful?