Can anyone tell me what might be wrong with this code? It's supposed to be a single-element queue, with blocking put and get methods. It seems to work just fine "most of the time", but on Windows, with two consumers (and one producer) I find that one of the consumer threads, just sometimes, sleeps forever in the wait, apparently never waking up (even if the other consumer thread is off busy, and not waiting in the get() method).
Yes, I know that I should be using a BlockingQueue for this, but this is a learning exercise, and I'm puzzled how it can fail like this. What (probably obvious!) did I miss?
The answer MAY be in the code you posted, but I'm too lazy to try to figure out multi-threading code without a complete SSCCE. In particular, are all your producers and consumers using the SAME RunnableQueue?
Also, when you say, "one of the consumer threads, just sometimes, sleeps forever in the wait, apparently never waking up," how are you determining this, and why do you expect it to wake up?
Joined: Dec 08, 2004
Indeed, I was (kinda) hoping that I had done something clearly idiotic, but now it's looking like the problem is actually in other parts of the system. Most likely, it looks like the browsers (Chrome, FF, IE, etc.) that are creating the requests that are being packaged as Runnables and passed into a thread pool .. those browsers are doing some strange things opening sockets that then don't do anything (I'm certain that Chrome is doing that at least) and I think that those oddities are creating unexpected behavior elsewhere.