About Question enthuware.ocpjp.v8.2.1708 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
AungKNyar
Posts: 5
Joined: Mon Jan 14, 2019 11:16 pm
Contact:

About Question enthuware.ocpjp.v8.2.1708 :

Post by AungKNyar »

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.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1708 :

Post by admin »

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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 73 guests