• 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

wait(),notify() problem

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone please explain these methods wait(),notify() and notifyall()
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is your question? Just read the documentation of the Object class.
There are many topics about these functions and many webpages explaining them.
 
Sonali Sehgal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone explain what does wait() and notify() are used in a java program.How do they coordinate with each other??
 
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

Sonali Sehgal wrote:can someone explain what does wait() and notify() are used in a java program.How do they coordinate with each other??



The wait() and notify() methods implemention notifications between threads. In Threading speak, they implement the condition variable functionality.

So... How much threading do you know? Do you understand synchronization? And of course, condition variables? Anyway, the Sun tutorial on threading is a good place to start....

http://java.sun.com/docs/books/tutorial/essential/concurrency/

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


In the above program how can someone explain how does wait() and notify() coordinate with each other...This program executes successfuly and the output is
:-
Waiting for b to complete....
Notification received
waiting done
Total is: 4950

This is a kathy sierra question....My question is why does notifcation is received prior to waiting done...???....How does both work in relation with each other...
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: The correct way to use the "Code" button is to click it ONCE (do not double click it!) so that a [ code ] start tag is inserted in your text; then paste the code, then click the "Code" button again ONCE so that a [ /code ] end tag is added.

Do not double-click the "Code" button, because that will insert a start and end tag after each other, and so your source code will not be in between the tags.
 
Sonali Sehgal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr Young, I will take care to click only once.......................
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When notify() is reached, the thread waiting on that object will be notified (ThreadA in this case).

So ThreadA will be moved into the pool of live threads, but it won't be running until ThreadB has finished;

this is because ThreadB hasn't released the lock yet and ThreadA needs b's lock before moving to System.out.println("waiting done") which is contained in a block synchronized on b.
 
Sonali Sehgal
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Massimo...I understood this topic.................Thanks for clarification...
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, 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