You can using synchronized to lock multi Thread program with process thread by thread
Example code for using synchronized block and synchronized method
synchronized method
public synchronized void testMethod(String obj){
// you method logic
}
synchronized block
public void testMethod(String obj){
// your method logic
synchronized(this){
// your method logic
// your method logic
}
// your method logic
// your method logic
synchronized(Test.class){
// your method logic
// your method logic
}
// your method logic
}