This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes locks in threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "locks in threads " Watch "locks in threads " New topic
Author

locks in threads

Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331
Hi,

I am not able to understand this passage from K&B, Can you please help me understand this:

Every object in Java has a built-in lock
that only comes into play when the object has synchronized method code. When
we enter a synchronized non-static method, we automatically acquire the lock
associated with the current instance of the class whose code we're executing (the
this instance). Acquiring a lock for an object is also known as getting the lock,
or locking the object, locking on the object, or synchronizing on the object.
Since there is only one lock per object, if one thread has picked up the lock, no
other thread can pick up the lock until the first thread releases (or returns) the lock.


my understanding is like this..that when a set of statements are to be executed in an atomic manner, except for one thread all other threads should not have access to the atomic section, and so the thread that executes the atomic section(synchronized method) takes up a lock...

[ December 10, 2007: Message edited by: Vishwa Nath ]
[ December 10, 2007: Message edited by: Vishwa Nath ]

Blog
 
Don't get me started about those stupid light bulbs.
 
subject: locks in threads