• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

help needed in Hashtable reading and removing files.

 
Ranch Hand
Posts: 40
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I need your help in solving a problem i am facing.

I am reading files from a particular folder and storing them into Hashtable(Key is filename and value is file object).

I need to read this Hashtable for a particular file extention. After getting particular file, i need to search associated files of first file in the same Hashtable. I need to store all these files in a list.

This part is working fine, but problem here is as i am reading the Hashtable sequentially, the same process will repeatin for the each associated file also. I tried to remove the associated files from Hashtable once they found but it is throwing

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.Hashtable$Enumerator.next(Unknown Source)
at HashEx.main(HashEx.java:33)

can anybody give some suggestions so that i can avoid of reading associated files.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bala,


.... but problem here is as i am reading the Hashtable sequentially, the same process will repeatin for the each associated file also. I tried to remove the associated files from Hashtable once they found but it is throwing

Exception in thread "main" java.util.ConcurrentModificationException
at java.util.Hashtable$Enumerator.next(Unknown Source)
at HashEx.main(HashEx.java:33)



From API about ConcurrentModificationException:


This exception may be thrown by methods that have detected concurrent modification of an object when such modification is not permissible.

For example, it is not generally permissible for one thread to modify a Collection while another thread is iterating over it.



I think synchronization will solve your problem.
[ June 11, 2008: Message edited by: Balasubramanian Chandrasekaran ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic