@Steve
I was considering whether to write this note or not. Although it's an old post, I felt it was still open.
Now that I'm actually working on the BlockingQueues, I am able to appreciate how indispensable the Poison kill approach is to have consumer know when to stop. It keeps my producers and consumers decoupled. Following was a stupid comment and a result of my ignorance.
I realize they use PoisonKill a lot many times in my current project and one of the default PoisonKill value they have here is the String "-999". But it's a different programming language ( a proprietary programming language). I didn't know there was a term for 'PoisonKill' values. I think it's a good idea depending on the implementation. For this case I think enum reference approach is better though. I say this because we are also setting Item content to the PoisonKill value and that is not where PoisonKill belongs.
By the way, here is my latest DelayedQueue implementation.
Pizza class - The raw type of elements.
package BlockingQueues.DelayedQueues;
import java.util.Objects;
DelayedPizza class-
DelayedPizzaProducer class
DelayedPizzaConsumer
And the PizzaScheduler class with the main method.
And here is my output.
run:
Thread-0 produced item 1 at 1375603968800
Thread-0 produced item 2 at 1375603968800
Thread-0 produced item 3 at 1375603968800
Thread-0 produced item 4 at 1375603968800
Thread-0 produced item 5 at 1375603968800
Thread-0 produced item 6 at 1375603968800
Thread-0 produced item 7 at 1375603968800
Thread-0 produced item 8 at 1375603968800
Thread-0 produced item 9 at 1375603968800
Thread-0 produced item 10 at 1375603968800
Thread-0 produced item 11 at 1375603968800
Thread-0 produced item 12 at 1375603968800
Thread-0 produced item 13 at 1375603968800
Thread-0 produced item 14 at 1375603968800
Thread-0 produced item 15 at 1375603968800
Thread-0 produced item 16 at 1375603968800
Thread-0 produced item 17 at 1375603968800
Thread-0 produced item 18 at 1375603968800
Thread-0 produced item 19 at 1375603968800
Thread-0 produced item 20 at 1375603968800
Thread-0 produced Poison Kill item -1 at 1375603968800
Thread-1 consumed Pizza with id 1 at time 1375603970800
Thread-1 consumed Pizza with id 2 at time 1375603970800
Thread-1 consumed Pizza with id 20 at time 1375603970800
Thread-1 consumed Pizza with id 19 at time 1375603970800
Thread-1 consumed Pizza with id 18 at time 1375603970800
Thread-1 consumed Pizza with id 17 at time 1375603970800
Thread-1 consumed Pizza with id 4 at time 1375603970800
Thread-1 consumed Pizza with id 15 at time 1375603970800
Thread-1 consumed Pizza with id 14 at time 1375603970800
Thread-1 consumed Pizza with id 13 at time 1375603970800
Thread-1 consumed Pizza with id 12 at time 1375603970800
Thread-1 consumed Pizza with id 11 at time 1375603970800
Thread-1 consumed Pizza with id 10 at time 1375603970800
Thread-1 consumed Pizza with id 9 at time 1375603970800
Thread-1 consumed Pizza with id 8 at time 1375603970800
Thread-1 consumed Pizza with id 7 at time 1375603970800
Thread-1 consumed Pizza with id 6 at time 1375603970800
Thread-1 consumed Pizza with id 5 at time 1375603970800
Thread-1 consumed Pizza with id 16 at time 1375603970800
Thread-1 consumed Pizza with id 3 at time 1375603970800
BUILD SUCCESSFUL (total time: 20 seconds)
Yipeeee!!!
Thank you..
Chan.