In ExecutorCompletionService we have take() and poll(). One blocks until queue has a future and other returns null if there is no future in Queue.But when to use take() vs poll() .Is there any special conditions for deciding this or we can go for any ??
You use poll() when there's something else your thread could do while it is waiting for something to show up in the queue. You write a loop that calls poll(), and then do either one thing or the other depending on whether poll() returns a value or not.
Using poll() in multi-threaded code IMO is a bit of code smell. It means that you have one thread that is doing two different things. Why not use two threads in that case?
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