K
Knute Johnson
I have a List that I need to access in two threads, in one thread I
clear, add and get the size of the List. The other just iterates over
the List. To prevent a ConcurrentModificationException, I can't allow
the list to be cleared or elements added when it is being iterated in
the other thread. My question is, will there be any problem using the
size() method unsynchronized in the thread that clears and adds
elements? Visibility shouldn't be a problem because all the changes to
the List occur in that thread.
Thanks,
clear, add and get the size of the List. The other just iterates over
the List. To prevent a ConcurrentModificationException, I can't allow
the list to be cleared or elements added when it is being iterated in
the other thread. My question is, will there be any problem using the
size() method unsynchronized in the thread that clears and adds
elements? Visibility shouldn't be a problem because all the changes to
the List occur in that thread.
Thanks,