aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: locks in threads
 
Similar Threads
What does monitor mean?
Thread
Threads Notes for Exams
A few questions on wait(), sleep(int) and InterruptedException
Lock for whole object? or only synchronized block?