i was reading synchronization from
http://javarevisited.blogspot.in/2011/04/synchronization-in-java-synchronized.html. i came across a point which i was not able to understand. i am stating it below:
Java synchronized block is better than java synchronized method in java because by using synchronized block you can only
lock critical section of code and avoid locking whole method which can possibly degrade performance. A good example of java synchronization around this concept is getInstance() method Singleton class.
my question is that the link says, synchronization block locks critical section of code(highlighted in bold in above paragraph). my confusion is that don't we lock objects as opposed to section of code. also the kb6 book says that once we enter a synchronized method we acquire lock on the object whose method code we are running, and further , no other
thread is allowed to enter any other SYNCHRONIZED METHOD of that object(non synchronized methods can be accessed by multiple threads). so my question is that when we use synchronization blocks and we acquire a lock on an object , say which does not have any synchronized method, then what is the thing on which we get mutual exclusive access ?