Synchronization is the mechanism to control access to shared resources in a multithreaded environment. A 'synchronized' block or method acquires a 'Monitor Lock' on an object, forcing other threads to wait until the lock is released. This ensures mutual exclusion but can impact performance due to contention.
A bathroom in a restaurant. Only one person can use it at a time (synchronized). Others wait outside for their turn. Once someone leaves and unlocks the door, the next person can enter.
What is a Deadlock? Provide a scenario and explain how you can detect and prevent it.