| Author |
Summary of wait() notify() join() and synchronized
|
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
Can someone summarize the relationships among the Object
methods wait() and notify(), the Thread method join() and key
word synchronized. (Am I missing any?) Thanks.
Jim ...
|
BEE MBA PMP SCJP-6
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
Hi Jim,
This is a pretty big topic; it has spawned many books. If I were you, I'd set aside an afternoon, and read though this tutorial at Sun's site, which is not only quite good, it's also quite modern -- it teaches you what you need to know in the most up-to-date fashion possible.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
Ernest : You bet I know that it's a huge topic. And
I've spent many afternoons (and nights) studying,
using and abusing these tools. I can write my own
summary, but a more expert view would sure be
helpful. Seriously, 100 words or less, please. I will
be studying the concurrency tutorial also.
Jim ...
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
|
I think it would be better for you to post your specific confusions about the topic after you've read the tutorials rather than asking a volunteer to try to write a chapter to a book that is not likely to be better than the tutorials. Don't you agree?
|
 |
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
Okay, I will do my own 100 word summary for your
comment. I'm not particularly confused but trying to
consolidate my high-level understanding of the Java
OO approach. Thanks for responding and stay tuned.
Jim...
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
Jim Hoglund wrote:Okay, I will do my own 100 word summary for your
comment.
Cool. I for one will look forward to this.
|
 |
Jim Hoglund
Ranch Hand
Joined: Jan 09, 2008
Posts: 525
|
|
Okay Pete here it is - about 200 words, however.
Jim ... ...
Threads & Data Consistency
An executing thread is time sliced by the JVM, from start() until the end of its
run() method. To run a thread after another thread completes, just join() the
other thread. Call yield() to pause a thread. This relinquishes some of its time
slices for use elsewhere. For consistency of shared data, a thread can check
the data, sleep() and then check again, until the data is ready. Except join(),
these Thread methods operate on Thread.currentThread().
To coordinate thread activities, or wait for consistent shared data, call wait() on
a shared object. Then, when an active thread calls notify() on the same object,
you can proceed, or check the shared data and then proceed. This works like
the check and sleep() loop above, but faster. It’s simpler because all objects
have wait() and notify() built in.
The synchronized key word causes threads to pause and wait for consistent data
without any method calls. Methods and code blocks can be synchronized. A
synchronized method locks its own object (this) before it proceeds, manipulates
the shared data and releases the lock when it returns. (A static method locks
the Class object.) For a synchronized code block, the object to be locked must
be explicitly identified.
|
 |
Ashuthosh san
Ranch Hand
Joined: Jan 28, 2009
Posts: 35
|
|
Hi Jim,
The information is very useful, Thanks!. Could you please share any example for these methods. I am bit confused how to use these methods.
Regards
San
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
|
Cool, and thanks!
|
 |
 |
|
|
subject: Summary of wait() notify() join() and synchronized
|
|
|