This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
following is paragraph from kb 6 book page no. 735.
With locks. 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
does this means that if an object does not have synchronized methods, we can't acquire lock on that object. if we can acquire the lock , then how we do that ?
according to me the answer is yes, we can acquire lock on any object in java whether it has synchronized methods or not. we can do so using synchronized blocks. please somebody confirm if this is right ???
I think your correct, you can think of the synchronized keyword on a method as simply being like having a synchronised block on the particular object say using "this" surrounding the entire method. I suspect that the book is getting at the fact that you don't need to synchronize on any object if you use the synchronized keyword for a method and by doing this it uses the "built-in lock".