Win a copy of Event Streams in Action this week in the Java in General forum!
  • 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Infinaite Loop on Cached collection in Multi threaded environment

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My application is running on tomcat with Spring and Hibernate framework. It use EHCache as a cache provider in service level. That means objects created by service classes put in to the cache. (Not hibernate Dao objects).

There are some collection objects (HashSet, ArrayList, HashMap) in these cached objects. Non of them are syncronized collections. All are not thread safe, but not modify by the application after put in to the cache.

I found infinite loop in many ocations when I loop through this collection. Some of the loops are Iterator loops and some others are old for loops run base on int index.

I mannaged to overcome one infinite loop by replasing a HashSet with Collections.synchronizedSet(new HashSet()). But I don't understand the real problem of using normal HashSet as it's never being modified by the application. (Does EHCache modify them?)

Please explain me if there are any concerns here using non-thread safe collections.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!