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.
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.
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?
Joined: Jan 09, 2008
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.
Joined: Feb 23, 2007
Jim Hoglund wrote:Okay, I will do my own 100 word summary for your
Cool. I for one will look forward to this.
Joined: Jan 09, 2008
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.