The Artima Developer Community
Sponsored Link

Java Buzz Forum
Difference between synchronized ArrayList and CopyOnWriteArrayList in Java?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
Difference between synchronized ArrayList and CopyOnWriteArrayList in Java? Posted: Jun 1, 2015 8:57 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: Difference between synchronized ArrayList and CopyOnWriteArrayList in Java?
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Though both synchronized ArrayList and CopyOnWriteArrayList provides you thread-safety and you can use both of them when your list is shared between multiple threads, there is a subtle difference between them, Synchronized ArrayList is a synchronized collection while CopyOnWriteArrayList is a concurrent collection. What this means? It means is that CopyOnWriteArrayList is designed keeping concurrency in mind and it is more scalable than synchronized ArrayList if  list is primarily used for reading. You know that ArrayList is not synchronized, so you cannot directly use it in a multi-threaded environment where you list is accessed and modified by multiple threads. In order to use ArrayList in such environment, you need to first get a synchronized list by calling Collections.synchronizedList(). This list achieves thread-safety by locking the whole collection, which means if one thread is reading from list and other is also reading from list, they will go one by one, but you know that multiple thread can read from object without any issue. CopyOnWriteArrayList leverages this knowledge and provides reading without lock, which means a much better performance if there are more reader threads and write is happening quite low. In short, main difference between synchronized ArrayList and CopyOnWriteArrayList comes form the fact how they achieve thread safety and how scalable they are.
Read more »

Read: Difference between synchronized ArrayList and CopyOnWriteArrayList in Java?

Topic: US sides with Oracle in Java copyright dispute with Google Previous Topic   Next Topic Topic: Puzzler: nested computeIfAbsent

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use