Yes, BlockingQueue add() and take() methods are thread safe , but with a difference .
add () and take() methods use 2 different ReentrantLock .
add( ) uses
private final ReentrantLock putLock = new ReentrantLock();
take() uses
private final ReentrantLock takeLock = new ReentrantLock();
Therefore, simultaneous access to the add() method is synchronized. Similarly, concurrent access to the take() method is synchronized .
But simultaneous access to the add() and take() methods is not synchronized since they use 2 different locking objects (except that the condition for the end of the queue is equal to / empty).
Amrish Pandey Feb 25 '14 at 6:19 2014-02-25 06:19
source share