0

I have a worker thread which uses a "LinkedBlockingQueue" to save the remaining command objects. The thread itself polls command of the queue and other threads can add commands. The calls to "poll" and "add" are wrapped in synchronized methods. Now i need to access the number of remaining commands in the queue. Do i need to synchronize the call to "size()"?.

This will be called very often, because I display the progress in the windows taskbar and i have the feeling that calling synchronized methods is a bit slow.

Richard Loth
  • 79
  • 1
  • 7
  • No, it's thread-safe. – Tunaki Apr 29 '16 at 12:16
  • Thx, I read a bit in the javadoc and use a "ConcurrentLinkedQueue" now. Thank God i worked on the "Queue" interface. Seems like I don't even need to synchronize the calls to "poll" and "add". – Richard Loth Apr 29 '16 at 12:23

0 Answers0