I am getting a ConcurrentModificationException on the following code:
private static List<Task> tasks = new LinkedList<Task>();
...
public void doTasks(){
synchronized(tasks){
Iterator<Task> it = tasks.iterator();
while(it.hasNext()){
Task t = it.next(); < Exception is always thrown on this line.
if(t.isDone()){
it.remove();
} else {
t.run();
}
}
}
}
...
public void addTask(Task t){
synchronized(tasks){
tasks.add(t);
}
}
...
public void clearTasks(){
synchronized(tasks){
tasks.clear();
}
}
The Object "tasks" is not used anywhere else in the class. I'm not sure why I'm getting the exception. Any help would be greatly appreciated.