Deadlock detection

When a transaction waits more than a specific amount of time to
obtain a lock (called the deadlock timeout), Derby can
detect whether the transaction is involved in a deadlock.

When Derby analyzes
such a situation for deadlocks it tries to determine how many transactions
are involved in the deadlock (two or more). Usually aborting one transaction
breaks the deadlock. Derby must
pick one transaction as the victim and abort that transaction; it picks the
transaction that holds the fewest number of locks as the victim, on the assumption
that transaction has performed the least amount of work. (This may not be
the case, however; the transaction might have recently been escalated from
row-level locking to table locking and thus hold a small number of locks even
though it has done the most work.)

When Derby aborts the
victim transaction, it receives a deadlock error (an SQLException with
an SQLState of 40001). The error message gives you
the transaction IDs, the statements, and the status of locks involved in a
deadlock situation.

Note: Deadlocks are detected only within a single database. Deadlocks across
multiple databases are not detected. Non-database deadlocks caused by Java
synchronization primitives are not detected by Derby.