1Z0-805J Free Dumps Study Materials
Question 5: 次のコード? フ ラグメントはあります:
List<Person> pList = new CopyOnWriteArrayList<Person>();
どのステートメントは真ですか。
A. リストへのゕクセスを読むことは同期させる必要があります。
B. リストへの書き込 みゕクセスは同期させる必要があります。
C. 一覧から検索され た Person オブジェク トはスレッドセーフです。
D. 一 覧 か ら 検 索 さ れ た Person オ ブ ジ ェ ク ト は 書 き 込 ま れ た と き に リ ス ト が コ ピ ー さ れ ま
す。
E. 複数のスレッドが安全に一覧から Person オブジェクトを削除することができます。
Correct Answer: C
Explanation:
CopyOnWriteArrayList produces a thread-safe variant of ArrayList in which all mutative operations
(add, set, and so on) are implemented by making a fresh copy of the underlying array.
Note: his is ordinarily too costly, but may be more efficient than alternatives when traversal
operations vastly outnumber mutations, and is useful when you cannot or don't want to
synchronize traversals, yet need to preclude interference among concurrent threads. The
"snapshot" style iterator method uses a reference to the state of the array at the point that the
iterator was created. This array never changes during the lifetime of the iterator, so interference is
impossible and the iterator is guaranteed not to throw ConcurrentModificationException. The
iterator will not reflect additions, removals, or changes to the list since the iterator was created.
Element-changing operations on iterators themselves (remove, set, and add) are not supported.
These methods throw UnsupportedOperationException.
All elements are permitted, including null.
Memory consistency effects: As with other concurrent collections, actions in a thread prior to
placing an object into a CopyOnWriteArrayList happen-before actions subsequent to the access or
removal of that element from the CopyOnWriteArrayList in another thread.
Reference: java.util.concurrent.CopyOnWriteArrayList<E>