The methods wait() and notify(), remember, are instance methods of Object.
In the same way that every object has a lock, every object can have a list of threads
that are waiting for a signal (a notification) from the object. A thread gets on
this waiting list by executing the wait() method of the target object.
From that moment, it doesn't execute any further instructions until the notify() method of
the target object is called. If many threads are waiting on the same object, only one
will be chosen (in no guaranteed order) to proceed with its execution. If there are
no threads waiting, then no particular action is taken.
Hi to all in the preceding explanations are taken from K&B book as you know.
What is confused my mind is ; bolded part of explanations.
Ok . l understand that "In the same way that every object has a lock" this is clear
but what does K&B book mean by saying "every object can have a list of threads"
I understand something from that sentence (every object can have a list of threads) let me explain what l understand from this sentence.
Check please my answer, is it true?
please check the preceding code part. My comment about preceding code part is;
K&B book means "ThreadA" class has four thread (ThreadB,ThreadC,ThreadD,ThreadE) by saying every object can have a list of threads
is my comment is thrue for "every object can have a list of threads" sentence.
every object can have a list of threads ====>>> that are waiting for a signal (a notification) from the object <<<====.
Consider also that "can" is a relative term. A J2EE service request handler can technically spawn threads. But the J2EE standard forbids doing so (and if you ignore the standard, you may crash the server!)
Customer surveys are for companies who didn't pay proper attention to begin with.
English is a funny language. The problem is that the word has is very overloaded. Has denotes that there is some sort of relationship between 2 things, however, it is frequently used to denote possesion. So, for example the sentence I have a pen is really means I posses a pen. You can also say The Pen has me as a owner. But that doesn't mean that the pen possesses me . Here has means that there is some sort of relationship between the pen and me, and you need to look somewhere else in the sentence ("as a owner") to figure out what the relationship is
Here, the sentence every object can have a list of threads that are waiting for a signal is used in the same sense as The Pen has me as a owner. The object doesn't posses the threads. All it means is that there is a relationship between object and the threads.
This is usually they tell you not to use passive voice when you want to write clearly. A sentence written in passive voice is grammatically correct. It just causes confusion
Joined: Apr 23, 2013
Really thanks a lot "Jayesh A Lalwani" and "Tim Holloway" for your valuable explanations.They really opened me new horizons.
But this time l want to ask you about below two sentences
First (my mind is confused.What does just below sentence want to express )
For a thread to call wait() or notify(), the thread has to be the owner of the lock for that object.
And second just below sentence.l have an opinion.Please check whether l am right ;;;
--> when any thread execute the wait() metod of target object that thread will start waiting and in this situation another threads can not enter the synchronized block normaly
but in this case the thread which is currently waiting notification from target object, temporarily releases the lock and now in this situation other threads also can enter the synchronized block
and also if other threads execute wait() method they also start to wait for notification.
When the thread waits, it temporarily releases the lock for other threads to use, but it will need it again to continue execution.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com