• 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

wait and notifyAll

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi
This Question is from ExamLab ..
Output is Ready to Print, Now Printing.

I am little bit confused in use of wait and notify and notifyAll. why it's not sending notification to above wait...
and if i want to send notification to a above wait then what i suppose to change and why?

Many Thanks
 
Ranch Hand
Posts: 310
1
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Afzal Rehman wrote:
Hi
This Question is from ExamLab ..
Output is Ready to Print, Now Printing.

I am little bit confused in use of wait and notify and notifyAll. why it's not sending notification to above wait...
and if i want to send notification to a above wait then what i suppose to change and why?

Many Thanks




t.notifyAll() will send a notification to all threads waiting for object "t". Here wait is not called on object t, so the notification will never come and it will go to an infinite wait..
If you change the code to t.wait() on a synchronized (t), the t.notifyAll() will give notification to wait() and the wait() ends. please try the code below:

 
Afzal Rehman
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rajeev
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your original line 13, wait() is called on "this", which is totally fine. But it didn't work as you expected because t in line 17 refers not to instance of Trd referenced by that "this", but to instance of Thread. If you introduce reference Trd t0=new Trd() and use t0 in line 22 & 24 instead of t, it will work.
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Try this, Hope you will understand!

wait(), notify(0, notifyAll() should be called for the same object, else, there are communication between Threads.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic