QuizzesPessimistic Locking — Concept Check
intermediate
hibernate

Pessimistic Locking — Concept Check

Questions on Pessimistic Locking. PESSIMISTIC_READ (shared lock) and PESSIMISTIC_WRITE (exclusive lock) via EntityManager.lock() or query lock hints prevent concurrent modification at the DB level.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Pessimistic Locking — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A developer is implementing a ticket booking system where double-booking must be avoided. Which locking strategy should they use?

    • APESSIMISTIC_READ to allow read access
    • BNo locking, rely on application logic
    • COPTIMISTIC locking for low contention
    • DPESSIMISTIC_WRITE to prevent concurrent bookings
  2. 2.In a high-contention inventory system, why might you choose pessimistic locking over optimistic locking?

    • ATo increase read performance
    • BTo reduce database load
    • CTo allow multiple concurrent writes
    • DTo avoid retries due to OptimisticLockException
  3. 3.A service uses PESSIMISTIC_READ for price calculations. What is the effect?

    • APrevents all other reads and writes
    • BPrevents other writes but allows reads
    • CAllows all transactions without restriction
    • DCauses immediate failure if lock is unavailable
  4. 4.A developer uses PESSIMISTIC_WRITE with NOWAIT. What happens if the lock is unavailable?

    • AWaits indefinitely for the lock
    • BProceeds without acquiring the lock
    • CAutomatically retries the transaction
    • DThrows PessimisticLockException immediately
  5. 5.Why might PESSIMISTIC_WRITE be preferred for a financial transaction system?

    • AReduces the need for database locks
    • BPrevents lost updates in high-contention scenarios
    • COptimizes for low contention environments
    • DAllows concurrent reads and writes
  6. 6.In a job queue, why use PESSIMISTIC_WRITE with SKIP LOCKED?

    • ATo ensure all jobs are processed in order
    • BTo allow concurrent job processing
    • CTo increase the priority of locked jobs
    • DTo avoid processing jobs already locked by others
  7. 7.A developer mistakenly believes PESSIMISTIC_READ blocks all access. What is the truth?

    • AIt does not block any access
    • BIt allows writes but blocks reads
    • CIt allows reads but blocks writes
    • DIt blocks all reads and writes
  8. 8.What is the difference between PESSIMISTIC_WRITE and PESSIMISTIC_READ?

    • AWRITE allows all access; READ blocks all access
    • BBoth block all access
    • CREAD blocks all access; WRITE blocks writes only
    • DWRITE blocks all access; READ blocks writes only