File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Every object can have a list of threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Every object can have a list of threads" Watch "Every object can have a list of threads" New topic
Author

Every object can have a list of threads

salih ayan
Ranch Hand

Joined: Apr 23, 2013
Posts: 59





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.


Thanks to all explanations.





Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

You didn't read the whole 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.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2271
    
  28

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
salih ayan
Ranch Hand

Joined: Apr 23, 2013
Posts: 59
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.



please help.
Thanks again
 
Consider Paul's rocket mass heater.
 
subject: Every object can have a list of threads
 
Similar Threads
Insights into synchronization
notify() question from Nikos
Threads 001
Object Locks
wait(), notify() doubts