What is your question? Just read the documentation of the Object class.
There are many topics about these functions and many webpages explaining them.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
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....
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...
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.
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.