Menu

#5 ConcurrentModificationException

open
nobody
None
5
2012-01-20
2012-01-20
Anonymous
No

Hi!

This just happened to me:

Exception in thread "xxx" java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:793)
at java.util.HashMap$ValueIterator.next(HashMap.java:822)
at name.pachler.nio.file.impl.BSDPathWatchService.pollImpl(BSDPathWatchService.java:386)
at name.pachler.nio.file.impl.BSDPathWatchService.take(BSDPathWatchService.java:281)
at xxx
at xxx
at java.lang.Thread.run(Thread.java:680)

I'm trying to recursively watch a directory tree (20 directories in total). I'm basically running this loop in a separate thread:
a) walk the tree, registering all directories for watching
b) watchService.take()
c) someEvent.notifyAll()

The other thread accessing watchService is when the bean is destroyed, I do a watchService.close(). But this did not happen here. I'm gonna dig into BSDWatchService and see if I find the error.

Kind regards,
Kosta

Discussion

  • Uwe Pachler

    Uwe Pachler - 2012-01-20

    At first glance I find this rather puzzling. All access to the keys member of BSDPathWatchService is synchronized via the changeLock.

    So this shoudln't be happening in another thread, which leaves concurrent modification in the for loop itself - and it doesn't look like that either.

    Would be nice if you could isolate this into a unit test, so I can integrate it into the suite.

    You could also test if this happens with 0.94 (I'm assuming you're using 0.95, are you?)

    Cheers,

    Uwe

     
  • Anonymous

    Anonymous - 2012-01-23

    Yes, after looking through the BSDPathWatchService, I was puzzled, too. I could not find anything that could cause such an Exception.

    Yes, I am using 0.95. I am currently working on a unit test to isolate this problem. I will let you know if I find anything.

     
  • Anonymous

    Anonymous - 2012-01-23

    Ok, the problem was me not calling WatchKey.cancel() on a key that was deleted / moved elsewhere. Calling cancel() made the Exception disappear.

    I can still create a unit test for you if you want. I am still puzzled where the ConcurrentModificationException came from.

     
  • Uwe Pachler

    Uwe Pachler - 2012-01-23

    Hi,

    A unit test would be absolutely awesome, as you'd save me the trouble. Simply paste it here, I'll put it into JDK7Test.java and see what I can make out of it.

    Thanks,

    Uwe

     

Log in to post a comment.

MongoDB Logo MongoDB