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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: locks in threads
 
Similar Threads
A few questions on wait(), sleep(int) and InterruptedException
Threads Notes for Exams
Lock for whole object? or only synchronized block?
What does monitor mean?
Thread