# java.sql.SQLException: Lock time out. The lock request timed out because another transaction holds a conflicting lock.

- **ID:** `java/derby-lock-timeout`
- **Domain:** java
- **Category:** resource_error
- **Error Code:** `DERBY-1000`
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

A database transaction is waiting for a lock held by another transaction and exceeds the configured lock timeout, typically due to long-running transactions or deadlocks in embedded Derby databases.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Apache Derby 10.14 | active | — | — |
| Apache Derby 10.15 | active | — | — |
| Apache Derby 10.16 | active | — | — |

## Workarounds

1. **Set a shorter lock timeout using Derby system property derby.locks.waitTimeout=30 (in seconds) to fail fast and retry the transaction.** (80% success)
   ```
   Set a shorter lock timeout using Derby system property derby.locks.waitTimeout=30 (in seconds) to fail fast and retry the transaction.
   ```
2. **Optimize transaction scope: commit or rollback transactions as early as possible to release locks. For example, in JDBC code, use try-with-resources to ensure auto-close and commit.** (85% success)
   ```
   Optimize transaction scope: commit or rollback transactions as early as possible to release locks. For example, in JDBC code, use try-with-resources to ensure auto-close and commit.
   ```
3. **Use isolation level READ_COMMITTED instead of REPEATABLE_READ to reduce lock contention. Set connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED).** (75% success)
   ```
   Use isolation level READ_COMMITTED instead of REPEATABLE_READ to reduce lock contention. Set connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED).
   ```

## Dead Ends

- **Restart the database server or application** — Restarting clears all locks but does not fix the underlying transaction logic that causes contention; the problem will recur. (90% fail)
- **Increase the lock timeout to a very high value (e.g., 600 seconds)** — A higher timeout delays the error but does not resolve the conflict; the transaction may still time out or cause performance degradation. (70% fail)
- **Use a different database driver version** — The lock timeout is a database-level behavior, not a driver issue; changing drivers does not affect locking mechanisms. (85% fail)
