Synchronized methods and blocks -III

Synchronized Blocks

It allows execution of arbitrary code to be synchronized with lock of an arbitrary object. Once a thread reached on synchronized code block after acquiring lock on specified object, other threads will not be able to execute code block or any code requiring same object lock until it is not released by current thread, code block completes normally or uncaught exception is thrown.

Possible Output is listed as below :
Increased : 0
Increased : 1
Increased : 2
Increased : 3
Increased : 4
Increased : 5
Increased : 6
Increased : 7
Increased : 8
Increased : 9
Exit from main().
Decreased : 10
Decreased : 9
Decreased : 8
Decreased : 7
Decreased : 6
Decreased : 5
Decreased : 4
Decreased : 3
Decreased : 2
Decreased : 1

No Responses