I have an ArrayList of Routine objects and I must use this method to update the various status of the task
while(!allRoutineComplete){
for (Routine routine : routineList) {
if(!(routine.isBlocked()) && !(routine.isFinished())) {
routine.run();
}
}
for (Routine routine : routineList) {
routine.updateStatus();
if(routine.isFinished()){
completedRoutineNumber++;
}
if(completedRoutineNumber==routineList.size()){
allRoutineComplete=true;
}
}
}
unfortunately the boolean allRoutineComplete in the my implementation is setted as true before the finish of all the Routine.
What is wrong in my code?
How to check efficently the finish of all tasks?
You must move the all Routine Complete check, in the first
forcycle, otherwise the routine finished loop more times.Try to use this: