WeakHashMap iteration and garbage collection

Posted by Shamik on Stack Overflow See other posts from Stack Overflow or by Shamik
Published on 2010-05-18T21:51:45Z Indexed on 2010/05/18 22:00 UTC
Read the original article Hit count: 157

Filed under:

I am using a WeaekHashMap to implement a Cache. I am wondering if I am iterating over the keys of this map, and at the same time garbage collector is actively removing keys from this map, would I receive a ConcurrentModificationException ? I do not think so, because as far as I understand, concurrentmodificationexception happens because of bugs in the application code where the developer forgot to understand that the same map is shared/used by other threads and in this case, it should not happen. But wondering how would JVM handle this when WeakHashMap is not synchronized ?

© Stack Overflow or respective owner

Related posts about java