Synchronization in Java is a mechanism that controls how multiple threads access shared resources, ensuring that only one thread can execute a critical section of code at a time.
It prevents race conditions and data corruption when threads read and modify shared data concurrently
class Counter {
private int count = 0;
public synchronized void increment() {
count++; # Only one thread can execute this at a time per Counter instance
}
}