Skip to main content

πŸ—“οΈ 07082025 1052
πŸ“Ž

pessimistic_locking

β€œAssume conflict will happen. Lock early.”

🧰 Mechanism:​

  • Acquire lock before accessing data
  • Other transactions block until lock is released

🟒 Pros:​

  • Safe: avoids conflicts
  • Good for high-contention systems

πŸ”΄ Cons:​

  • Can lead to deadlocks
  • Lower concurrency
  • Blocking = slower performance

πŸ› οΈ Common in:​

  • Traditional RDBMS (e.g., SELECT ... FOR UPDATE)
  • Critical sections in threads (synchronized, ReentrantLock)

References

  • ChatGPT