Configuring deadlock detection and lock wait timeouts

You configure the amount of time a transaction waits before Derby does any deadlock checking with the derby.locks.deadlockTimeout property.

You configure the amount of time a transaction waits before timing out with the derby.locks.waitTimeout property. When configuring your database or system, you should consider these properties together. For example, in order for any deadlock checking to occur, the derby.locks.deadlockTimeout property must be set to a value lower than the derby.locks.waitTimeout property. If it is set to a value equal to or higher than the derby.locks.waitTimeout, the transaction times out before Derby does any deadlock checking.

By default, derby.locks.waitTimeout is set to 60 seconds. -1 is the equivalent of no wait timeout. This means that transactions never time out, although Derby can choose a transaction as a deadlock victim.

In the following figure, derby.locks.deadlockTimeout is set to 30 seconds, while derby.locks.waitTimeout has no limit.

Figure 1. Configuration with deadlock checking after 30 seconds and no lock wait timeouts
This figure shows a configuration in which transactions are never aborted unless they are selected as the victim when deadlocks are checked. If at 30 seconds there is no deadlock, the transaction will wait until it can obtain a lock (or forever).

In the following figure, derby.locks.deadlockTimeout is set to 60 seconds, while derby.locks.waitTimeout is set to 90 seconds.

Figure 2. Configuration with deadlock checking after 60 seconds and lock wait timeout at 90 seconds
This figure shows a configuration where deadlock checking occurs after a transaction has waited 60 seconds for a lock. After it has waited for 90 seconds, the transaction times out and is rolled back.

In the following figure, derby.locks.deadlockTimeout is set to 60 seconds, while derby.locks.waitTimeout is set to 50 seconds, lower than the deadlock timeout limit.

Figure 3. Configuration with no deadlock checking and a 50-second lock wait timeout
This figure shows a configuration where no deadlock checking occurs. The transactions time out after they have waited 50 seconds.
Related concepts
Avoiding deadlocks
Deadlock detection
Lock wait timeouts
Debugging deadlocks
Programming applications to handle deadlocks