• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

A question of wait() and notifyAll()

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I have a question of wait() and notifyAll(). I understand all the threads need in the loop need to be in a synchronized block to lock the object. Now I have a small code using singleton to be a lock, but it doesn't work properly when invoke notifyAll().


While running the code, the waiting threads are not able to be wake up. What's the problem? Please help.

Thanks
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

While running the code, the waiting threads are not able to be wake up. What's the problem? Please help.



Your thread that sends the notifications, is *not* releasing the lock. The threads do wakeup. They just can't get the synchronization lock, hence, remain blocked.

Henry
 
L. Wei
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right! It actually release the lock but quickly regain the lock again. When I change the class PlayThread2 to

It works properly

Originally posted by Henry Wong:


Your thread that sends the notifications, is *not* releasing the lock. The threads do wakeup. They just can't get the synchronization lock, hence, remain blocked.

Henry

 
Is this the real life? Is this just fantasy? Is this a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic