@Scheduled(fixedDelay=3_600_000)// Execute this method 1 hour after the last execution, in order for some tasks to have been gathered.
//@Scheduled(fixedDelay = 20_000) // Just for testing (every 20 secs).
publicvoidexecuteBackgroundTasks()
{
List<Callable<Boolean>>tempList=newArrayList<>(FullTextsServiceImpl.backgroundCallableTasks);// Copy the list in order to know what was executed and delete only that data later.
// So the items added while this execution happens, will be left in the list, while the other will be deleted.
intnumOfTasks=tempList.size();// Since the temp-list is a deep-copy and not a reference, new tasks that are added will not be executed.
if(numOfTasks==0)
return;
logger.debug(numOfTasks+" background tasks were found inside the \"backgroundCallableTasks\" list and are about to be executed.");
logger.error("Task_"+(i+1)+" was cancelled: "+ce.getMessage());
}catch(IndexOutOfBoundsExceptionioobe){
logger.error("IOOBE for task_"+i+" in the futures-list! "+ioobe.getMessage());
}finally{
FullTextsServiceImpl.backgroundCallableTasks.remove(tempList.get(i));// Remove this object from the global list. Do not use indexes, since they will be different after each deletion and addition.