DERBY-1000 java resource_error ai_generated partial

java.sql.SQLException: 锁超时。锁请求超时,因为另一个事务持有冲突的锁。

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

ID: java/derby-lock-timeout

其他格式: JSON · Markdown 中文 · English
82%修复率
85%置信度
1证据数
2024-01-20首次发现

版本兼容性

版本状态引入弃用备注
Apache Derby 10.14 active
Apache Derby 10.15 active
Apache Derby 10.16 active

根因分析

数据库事务正在等待另一个事务持有的锁,并超过了配置的锁超时时间,通常是由于嵌入式 Derby 数据库中的长时间运行事务或死锁。

English

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.

generic

官方文档

https://db.apache.org/derby/docs/10.15/ref/rrefexceptlocktimeout.html

解决方案

  1. 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.
  3. Use isolation level READ_COMMITTED instead of REPEATABLE_READ to reduce lock contention. Set connection.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED).

无效尝试

常见但无效的做法:

  1. Restart the database server or application 90% 失败

    Restarting clears all locks but does not fix the underlying transaction logic that causes contention; the problem will recur.

  2. Increase the lock timeout to a very high value (e.g., 600 seconds) 70% 失败

    A higher timeout delays the error but does not resolve the conflict; the transaction may still time out or cause performance degradation.

  3. Use a different database driver version 85% 失败

    The lock timeout is a database-level behavior, not a driver issue; changing drivers does not affect locking mechanisms.