Reputation: 9765
What are the other ways of making an arraylist synchronized without using Collections.synchronizedList()
?
Upvotes: 1
Views: 593
Reputation: 458
ConcurrentLinkedQueue is not a List
but it is thread safe while accessing to its elements.
Upvotes: 0
Reputation: 10882
Consider using CopyOnWriteArrayList
or other concurrent collections from java.util.concurrent
. Also, Vector
is in essence synchronized ArrayList
, but this also means that it's basically the same as ArrayList
wrapped with Collection.synchronizedList()
.
If you want us to help you with choosing appropriate collection, please specify details of your task.
Upvotes: 1
Reputation: 395
i hope there are 2 ways ,
extends arraylist to your own class and override each method make it thread safe to enable synchronization
user CopyOnWriteArrayList which is another thread safe version of arraylist.
Upvotes: 1
Reputation: 133639
The method Collection.synchronizedList()
just wraps an existing List
by synchronizing all methods that can be accessed from a client class on a single mutex.
Nothing more nor less, if you want to emulate the behavior, the simplest way is to do exactly the same. But I don't see the point in doing it.
Upvotes: 4