Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

does BlockingQueue need synchronized? [duplicate]

Tags:

java

could you help me? Is this necessery for BlockingQueue, when I want to be sure that only one thread modify queue?:

BlockingQueue queue = new ArrayBlockingQueue(1024);

Collections=Collections.synchronizedCollection(queue); <--- is this necessary?

like image 896
newuser_java Avatar asked Jan 24 '26 19:01

newuser_java


1 Answers

Since BlockingQueue is thread safe, you do not need to synchronize its accesses: the concurrency is handled by the class itself.

The BlockingQueue javadoc states:

BlockingQueue implementations are thread-safe.

It also provides a producer - consumer example.

like image 87
Jean Logeart Avatar answered Jan 26 '26 09:01

Jean Logeart