1

What are the other ways of making an arraylist synchronized without using Collections.synchronizedList() ?

2
  • 5
    What do you mean? Why do you want this? Commented Jul 29, 2015 at 17:26
  • 1
    What exactly are you asking? What have you got against the method you mentioned? Describe exactly why that won't work for you. Commented Jul 29, 2015 at 17:28

4 Answers 4

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

i hope there are 2 ways ,

  1. extends arraylist to your own class and override each method make it thread safe to enable synchronization

  2. user CopyOnWriteArrayList which is another thread safe version of arraylist.

Comments

1

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

0

ConcurrentLinkedQueue is not a List but it is thread safe while accessing to its elements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.