It serializes access to shared resources by locking.
Race conditions occur when multiple threads access shared data simultaneously, leading to inconsistent results. The 'synchronized' keyword ensures that only one thread at a time can execute a particular block of code or method, effectively serializing access to shared resources and preventing race conditions. In a flash sale system, using 'synchronized' on inventory update ensures each update is atomic.