What are the other ways of making an arraylist synchronized without using Collections.synchronizedList() ?
-
5What do you mean? Why do you want this?Louis Wasserman– Louis Wasserman2015-07-29 17:26:22 +00:00Commented Jul 29, 2015 at 17:26
-
1What exactly are you asking? What have you got against the method you mentioned? Describe exactly why that won't work for you.Boris the Spider– Boris the Spider2015-07-29 17:28:51 +00:00Commented Jul 29, 2015 at 17:28
4 Answers
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.
Comments
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.
Comments
ConcurrentLinkedQueue is not a List but it is thread safe while accessing to its elements.