• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can't get "wait-notify" to work in simple program.  RSS feed

 
Sven Sylta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm experimenting with "wait-notify" but it's not working. I want the program to output the text "It's working" whenever I type the letter n in the console. What am I doing wrong? Thanks.

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To properly signal between threads you need to synchronize and signal using a shared object. In your sample you have two different Runnable instances each synchronizing and signaling on itself. So neither of the two tasks will see signals from the other one. You need to provide some shared object to signal with.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!