F
Frank Fredstone
If I have something like:
for (Object o : c) {
synchronized(o) {
// code that takes an hour to run
}
}
I assume another thread could remove the object referenced by o before
the synchronized block is entered, right? Even if c is
ConcurrentHashMap.keySet().
If that's true and I can't have other threads wait for the entire
collection to be iterated over, I guess Iterator would be the wrong
choice. Is that right?
for (Object o : c) {
synchronized(o) {
// code that takes an hour to run
}
}
I assume another thread could remove the object referenced by o before
the synchronized block is entered, right? Even if c is
ConcurrentHashMap.keySet().
If that's true and I can't have other threads wait for the entire
collection to be iterated over, I guess Iterator would be the wrong
choice. Is that right?