Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all queues in Java thread-safe? [closed]

There exists many queue implementations in Java like LinkedList, BlockingQueues. Are all of them thread-safe? If your answer no, which implementations support concurrent access and which gives the best performance?

Note: I'm using JDK 1.6.

like image 625
ovunccetin Avatar asked Dec 04 '22 13:12

ovunccetin


1 Answers

Most standard collections are not thread safe. You find this information when reading the API documention.

For example the documentation of LinkedList:

If multiple threads access a linked list concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally

For collections that are accessed from multiple threads you should look at the java.util.concurrent package

like image 188
micha Avatar answered Dec 30 '22 12:12

micha