• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

wait/notifyAll not behaving as I expected

 
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

TIA,
Toby

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Toby Eggitt
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

So, sorry to have bothered y'all,
Cheers,
Toby
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It did occur to me that calling "put(null)" would put a stick in the system's spokes; the code doesn't reject that if it's tried.
 
Toby Eggitt
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's a fair observation! Not the problem I've been witnessing, but a very fair comment all the same. Thanks!
 
That which doesn't kill us makes us stronger. I think a piece of pie wouldn't kill me. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic