Synchronizing a Block of Code
now we ae discussing about syncronised the block of code .here many steps for that :
> Create a class and extend the Thread class.
> Override the run() method of Thread. This is where the synchronized block of code will go.
> For our three threaded objects to share the same object, we will need to create a constructor that accepts a StringBuffer object in the argument.
> The synchronized block of code will obtain a lock on the StringBuffer object from step 3.
> Within the block, output the StringBuffer 100 times and then increment the letter in the StringBuffer.
> Finally, in the main() method, create a single StringBuffer object using the letter A, then create three instances of our class and start all three of them.