Ok so for my server about a month ago I made cooking. I used only event manager and every thing worked fine. However out of the blue I am getting problems...
When I try to cook multiple fish (the 5 button for example) this is what happens.
Starts the cookingTimer(event), once the timer gets to 0, it goes to the cooking method(this second part is in the same method as the timer), it cooks the fish for the second time, HOWEVER, it wont start the event for the second time. Instead if gives me this.
Code:
Exception in thread "Thread-0" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:3
72)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at src.EventManager.run(EventManager.java:95)
at java.lang.Thread.run(Thread.java:619)
My guess was that it was because I was trying to run the same event at the same time. But even when I throw in a stop(), it still crashs.
If I just put the timer in the event though, and have it so it checks to see what the timer is at in process, then it works fine.
Here is my event if it helps.
Code:
public void cookingTimer(){
EventManager.getSingleton().addEvent(new Event() {
public void execute(EventContainer c) {
if(cookingTimer > 0)
cookingTimer--;
if(cookingTimer == 1)
Server.Cooking.secondStage(amountCooking, playerId);
c.stop();
}
}, 600);
}
Any help is great.
EDIT: I found a way around the problem although if any one can tell me why the above dosnt work it would be nice for learning. This works though, simply make the event run every 5 seconds rather then having a timer count, have the event count.
Code:
public void cookingTimer(){
EventManager.getSingleton().addEvent(new Event() {
public void execute(EventContainer c) {
//sM(""+cookingTimer+" "+cookingAmount+" "+amountCooked);
if(amountCooked == cookingAmount)
c.stop();
else if(amountCooked == 0){
} else
Server.Cooking.secondStage(cookingAmount, playerId);
}
}, 3000);
}