Synchronized Block in JavaSynchronized block can be used to perform synchronization on any specific resource of the method. Suppose you have 50 lines of code in your method, but you want to synchronize only 5 lines, you can use synchronized block. If you put all the codes of the method in the synchronized block, it will work same as the synchronized method. Points to remember for Synchronized block
Example of synchronized blockLet's see the simple example of synchronized block. Program of synchronized blockOutput:5 10 15 20 25 100 200 300 400 500 Same Example of synchronized block by using annonymous class://Program of synchronized block by using annonymous classOutput:5 10 15 20 25 100 200 300 400 500 Next TopicStatic Synchronization Example
|