Do I need extra synchronization when using a BlockingQueue?

No, you do not need to synchronize access to the object properties, or even use volatile on the member variables.

All actions performed by a thread before it queues an object on a BlockingQueue "happen-before" the object is dequeued. That means that any changes made by the first thread are visible to the second. This is common behavior for concurrent collections. See the last paragraph of the BlockingQueue class documentation:

Memory consistency effects: As with other concurrent collections, actions in a thread prior to placing an object into a BlockingQueue happen-before actions subsequent to the access or removal of that element from the BlockingQueue in another thread.

As long as the first thread doesn't make any modifications after queueing the object, it will be safe.


You don't need to do synchronization yourself, because the queue does it for you already.

Visibility is also guaranteed.


If you're sure that only one thread at a time will access your object, then you don't need synchronisation.

However, you can ensure that by using the synchronized keyword: each time you want to access this object and be sure that no other thread is using the same instance, wrap you code in a synchronized block:

Message myMessage = // ...
synchronized (myMessage) {
    // You're the only one to have access to this instance, do what you want
}

The synchronized block will acquire an implicit lock on the myMessage object. So, no other synchronized block will have access to the same instance until you leave this block.