You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Camunda ENGINE-16004异常求助:无法获取JDBC连接(3.5.5版本)

Camunda ENGINE-16004 数据库连接获取失败问题排查方案

使用camunda spring-boot-starter 3.5.5版本,近5天首次出现ENGINE-16004错误,核心触发原因是无法获取JDBC连接,错误发生在Camunda执行Job查询(JobEntity.selectNextJobsToExecute)时。

报错详情

ENGINE-16004 Exception while closing command context: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
### The error may exist in org/camunda/bpm/engine/impl/mapping/entity/Job.xml
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.JobEntity.selectNextJobsToExecute
### The error occurred while executing a query
### SQL: SELECT SUB.* FROM (     select       RES.* , row_number() over (ORDER BY RES.ID_ asc) rnk FROM ( select distinct RES.*      from ACT_RU_JOB RES      where (RES.RETRIES_ > 0)       and (               RES.DUEDATE_ is null or                   RES.DUEDATE_ <= ?       )    and (RES.LOCK_OWNER_ is null or RES.LOCK_EXP_TIME_ < ?)       and RES.SUSPENSION_STATE_ = 1                 and (      (      RES.EXCLUSIVE_ = 1           and not exists(             select J2.* from ACT_RU_JOB J2             where J2.PROCESS_INSTANCE_ID_ = RES.PROCESS_INSTANCE_ID_                                           -- from the same proc. inst.             and (J2.EXCLUSIVE_ = 1)         
-- also exclusive             and (J2.LOCK_OWNER_ is not null and J2.LOCK_EXP_TIME_ >= ?)  -- in progress             )    )     or      RES.EXCLUSIVE_ = 0        )            )RES ) SUB WHERE SUB.rnk >= ? AND SUB.rnk < ? ORDER BY SUB.rnk
### Cause: org.apache.ibatis.executor.ExecutorException: Error preparing statement.  Cause: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection.

排查步骤

  • 检查数据库连接池配置

    • 确认连接池最大连接数(如HikariCP的maximum-pool-size)是否满足业务需求,通过监控查看活跃连接数、等待队列长度,判断是否存在连接耗尽。
    • 调整连接超时(connection-timeout)配置,避免因数据库响应慢导致连接获取超时。
    • 启用连接有效性验证(如test-while-idle、validation-query),确保空闲连接可用,防止拿到失效连接。
  • 排查数据库端状态

    • 查看数据库连接数上限(如MySQL的max_connections)是否已达阈值,清理闲置连接或调整上限。
    • 检查数据库服务器CPU、内存、磁盘IO负载,确认是否因资源瓶颈导致无法响应连接请求。
    • 查看数据库日志,排查是否存在连接拒绝、超时或异常断开的记录。
  • 优化Camunda Job执行配置

    • 调整JobExecutor的线程池参数(core-threads、max-threads),避免线程过多占用连接资源。
    • 检查Job重试策略,限制失败Job的重试次数,防止反复重试占用连接。
    • 清理ACT_RU_JOB表中积压的无效Job,减少查询耗时和资源占用。
  • 检测应用侧连接泄漏

    • 排查自定义SQL操作是否存在未正确关闭连接的情况,确保连接被正常释放。
    • 启用连接池泄漏检测(如HikariCP的leak-detection-threshold),定位未释放的连接来源。

内容的提问来源于stack exchange,提问作者Vasil K

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 18:31:07