This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "locks in threads " Watch "locks in threads " New topic

locks in threads

Vishwanath Krishnamurthi
Ranch Hand

Joined: Jun 04, 2007
Posts: 331

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 ]

I agree. Here's the link:
subject: locks in threads
jQuery in Action, 3rd edition