Why does java.util.concurrent.LinkedBlockingQueue
have a head
and tail
reference as non volatile
?
Any change in head
or tail
in one thread may not be visible to another thread, so will this lead to issues?
The head
and tail
are going to be guarded by the putLock
or takeLock
. As long as your synchronize appropriately, you don't need to declare the fields as volatile
.
So, to answer your question. The fields don't need to be volatile
if they are correctly synchronized (which they are).
If there is a part of the code you find suspect, let me know, otherwise I cannot find any reason they need to be volatile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With