Java - Synchronized block and method in detail
Java is a multi-threaded programming language. So in every program multiple threads run in parallel to complete the program execution.At this point of time the results may differ or order of execution will change. To prevent the inaccuracy or inconsistency of data results, Java has provided 'synchronized' keyword to implement in 'synchronized block' and 'synchronized method'. The synchronized object won't allow two threads to access at the same time. So that one thread can't be reading while another updates it.The Second Thread should wait until the first is done.
Read more..