1synchronized blocks the next thread's call to method
2 as long as the previous thread's execution is not finished.
3 Threads can access this method one at a time.
4 Without synchronized all threads can access this method simultaneously.
1The synchronized keyword is all about different threads reading and writing
2to the same variables, objects and resources.
1public class MyCounter {
2
3 private int count = 0;
4
5 public synchronized void add(int value){
6 this.count += value;
7 }
8}
9