Zahid,
I am putting down the code here again. Could you please specify what doubt you have about the program. Basically synchronization can be undertaken either at the method level by specifying.
public void synchronized abc(){} // instance methods
public static void synchronized abc(){} // static methods
But the above line will make the Object in which this method exist synchronized. However suppose you have a ArrayList which you want to be synchronized. Then you have to use the second type like this
synchronized(myarraylist){
}
This will accquire a lock on the myarraylist object before it undertakes execution of the code in the block. Note that the mehtod in which this exist my itself may not be synchronized like this
public void abc(){
synchronized(myarraylist){
}
}
If you have any specific doubt please put it up.
Check out some good discussions on Threads
here