This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "Timer-0" java.util.ConcurrentModificationException  RSS feed

 
Rose Jac
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a swing application. And i am getting this error several times, even after changing the code. I am using a java.util.timer, to display moving circles in a panel and do certain functions depending on its position.
The timer starts and everything goes perfectly fine for about 5-10minutes and then, this error is shown:
How may I fix this?

Exception in thread "Timer-0" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at simulation.SceneDetails.setManetListForDesert(SceneDetails.java:325)
at simulation.nodePanel$1.run(SimualtionFrame.java:227)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)

Thanks.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the documentation for that exception?
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rose Jac wrote:I am running a swing application. And i am getting this error several times, even after changing the code. I am using a java.util.timer, to display moving circles in a panel and do certain functions depending on its position.
The timer starts and everything goes perfectly fine for about 5-10minutes and then, this error is shown:
How may I fix this?

Exception in thread "Timer-0" java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at simulation.SceneDetails.setManetListForDesert(SceneDetails.java:325)
at simulation.nodePanel$1.run(SimualtionFrame.java:227)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)

Thanks.


Hi Rose,

There is a possibilty of one thread modfying the list when other thread is iterating through the list...best way to fix this issue is put your Arraylist under sysnchronized block and have a check on each thread which access this list.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!