Hi ,
I am agree with Sanjeev Singh he has poured his knowledge on your problem.
I am going to explain basic of Synchronization.
Synchronization means set threads in a sequence that no more than one thread can access a single resource at a moment.So
java people launched this concept.There is no locking ability in java.it is only mechanism .Through java(JVM) you can only tell to operating system that we want lock on this object.So come on main topic
Synchronised a method and Synchronised a block are same having no difference. Same concept will be apply on method synchronisation as well as on block .Actually loading time every information regarding class load in memory.So method is member of class having some name .So it is already set by Java people that if Synchronised a method means lock must be accuired by that accessor object.but you think if need is to safe only 4 lines out of 50 lines of that method. then will you Synchronized whole method? So at this situation java people gave another concept means Synchronized block of code which is thread-unsafe.
By doing this you will get performance inhancement.
i think there is no need to explame it through example because Mr. Sanjeev Singh has explained it very well.
Thanks to John for asking it.
thanking to Sanjeev for nice explanation .
[ November 04, 2006: Message edited by: Prashant kumar Singh ]