The answer is: Both the threads will complete their operations successfully without getting any exception.
Is it because of CopyOnWriteArrayList<>()?
And two threads are operating on different lists? Copied one and the original one?
There are no explanations provided so I posted here.
About Question enthuware.ocpjp.v8.2.1708 :
Moderator: admin
-
- Posts: 5
- Joined: Mon Jan 14, 2019 11:16 pm
- Contact:
-
- Site Admin
- Posts: 10046
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1708 :
Yes, when you acquire an Iterator from CopyOnWriteArrayList, a copy of the underlying array of the data is created. The iterator uses this copy instead of the original one. That is why the add operation can work on the list at the same time another thread is iterating through the iterator.
An implication of this is that any modifications done to the list are not reflected in the Iterator and no modifications can be done on the list using that Iterator (such as by calling iterator.remove() ). Calls that try to modify the iterator will get UnsupportedOperationException.
An implication of this is that any modifications done to the list are not reflected in the Iterator and no modifications can be done on the list using that Iterator (such as by calling iterator.remove() ). Calls that try to modify the iterator will get UnsupportedOperationException.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 73 guests