Directly accessible data structure Java

The CopyOnWriteArrayList structure could solve your problem (java.util.concurrent).

  • CopyOnWriteArrayLists is thread-safe because all mutative operations are implemented by creating a copy of the list.

  • The problem of ConcurrentModificationException is avoided because the array doesn’t change while iterated. The so called snapshot style iterator uses a reference to the state of the array when the iterator was created.

  • If you have much more reads than writes, use CopyOnWriteArrayList, otherwise use Vector.

  • Vector introduces a small synchronization delay for each operation, when CopyOnWriteArrayList has a longer delay for write (due to copying) but no delay for reads.

  • Vector requires explicit synchronization when you are iterating it (so write operations can’t be executed at the same time), CopyOnWriteArrayList doesn’t.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)