Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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

 
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.
 
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?
 
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!