Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Summary of wait() notify() join() and synchronized

 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ...
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool, and thanks!
 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic