How does intrinsic locking in synchronized methods/blocks ensure thread safety?

  • It allows all threads to execute synchronized code simultaneously.
  • It doesn't affect thread safety.
  • It prevents all threads from executing synchronized code simultaneously.
  • It relies on hardware-specific instructions.
Intrinsic locking in synchronized methods/blocks ensures thread safety by preventing multiple threads from executing synchronized code simultaneously. When a thread enters a synchronized block, it acquires the lock associated with the synchronized object, preventing other threads from entering the same synchronized block until the lock is released. This ensures that only one thread can execute the synchronized code at a time, preventing data races and ensuring thread safety.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *