【异常】Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30005ms.
一、异常出现的场景
一次线上订单历史数据字段刷新操作,3张表100多万数据。由于同步更新太慢大概20分钟以上,所以采用异不的方式。代码如下:
private void batchUpdate(List<SaasOrderRecordDataForUpdate> saasOrderRecordDataForUpdateList, List<SaasServiceOrderInfoDataForUpdate> saasServiceOrderInfoDataForUpdateList, List<OrderGoodsDataForUpdate> orderGoodsDataForUpdateList, List<OrderAdditionCostInfoDataForUpdate> orderAdditionCostInfoDataForUpdateList) {
List<Future> asyncResultList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(saasOrderRecordDataForUpdateList)) {
int size = saasOrderRecordDataForUpdateList.size();
int count = size / ;
for (int i = ; i <= count; i++) {
List<SaasOrderRecordDataForUpdate> subList = null;
if (i == count) {
if ( * i < size) {
subList = saasOrderRecordDataForUpdateList.subList( * i, size);
}
} else {
subList = saasOrderRecordDataForUpdateList.subList( * i, * (i + ));
} if (CollectionUtils.isNotEmpty(subList)) {
Future future = dataRefreshJobServiceForAsync.batchUpdateSaasOrderRecordDataForUpdate(subList);
asyncResultList.add(future);
}
}
}
XxlJobLogger.log("批量更新订单数:{}", saasOrderRecordDataForUpdateList.size());
if (CollectionUtils.isNotEmpty(saasServiceOrderInfoDataForUpdateList)) {
int size = saasServiceOrderInfoDataForUpdateList.size();
int count = size / ;
for (int i = ; i <= count; i++) {
List<SaasServiceOrderInfoDataForUpdate> subList = null;
if (i == count) {
if ( * i < size) {
subList = saasServiceOrderInfoDataForUpdateList.subList( * i, size);
}
} else {
subList = saasServiceOrderInfoDataForUpdateList.subList( * i, * (i + ));
} if (CollectionUtils.isNotEmpty(subList)) {
Future future = dataRefreshJobServiceForAsync.batchUpdateSaasServiceOrderInfoDataForUpdate(subList);
asyncResultList.add(future);
}
} }
XxlJobLogger.log("批量更新订单服务数:{}", saasServiceOrderInfoDataForUpdateList.size());
if (CollectionUtils.isNotEmpty(orderGoodsDataForUpdateList)) {
int size = orderGoodsDataForUpdateList.size();
int count = size / ;
for (int i = ; i <= count; i++) {
List<OrderGoodsDataForUpdate> subList = null;
if (i == count) {
if ( * i < size) {
subList = orderGoodsDataForUpdateList.subList( * i, size);
}
} else {
subList = orderGoodsDataForUpdateList.subList( * i, * (i + ));
} if (CollectionUtils.isNotEmpty(subList)) {
Future future = dataRefreshJobServiceForAsync.batchUpdateOrderGoodsDataForUpdate(subList);
asyncResultList.add(future);
}
} }
XxlJobLogger.log("批量更新订单商品数:{}", orderGoodsDataForUpdateList.size());
if (CollectionUtils.isNotEmpty(orderAdditionCostInfoDataForUpdateList)) {
int size = orderAdditionCostInfoDataForUpdateList.size();
int count = size / ;
for (int i = ; i <= count; i++) {
List<OrderAdditionCostInfoDataForUpdate> subList = null;
if (i == count) {
if ( * i < size) {
subList = orderAdditionCostInfoDataForUpdateList.subList( * i, size);
}
} else {
subList = orderAdditionCostInfoDataForUpdateList.subList( * i, * (i + ));
} if (CollectionUtils.isNotEmpty(subList)) {
Future future = dataRefreshJobServiceForAsync.batchUpdateOrderAdditionCostInfoDataForUpdate(subList);
asyncResultList.add(future);
}
}
}
XxlJobLogger.log("批量更新订单附加费数:{}", orderAdditionCostInfoDataForUpdateList.size()); if (CollectionUtils.isNotEmpty(asyncResultList)) {
for (Future asyncResult : asyncResultList) {
try {
asyncResult.get();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
本地库刷新没问题,但是到了线上库就出现如下异常:
### Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool- - Connection is not available, request timed out after 30005ms.
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool- - Connection is not available, request timed out after 30005ms.
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:)
at sun.reflect.GeneratedMethodAccessor380.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:)
... more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool- - Connection is not available, request timed out after 30005ms.
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:)
at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:)
at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:)
at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:)
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:)
at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:)
at sun.reflect.GeneratedMethodAccessor381.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:)
at java.lang.reflect.Method.invoke(Method.java:)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:)
at com.sun.proxy.$Proxy521.update(Unknown Source)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:)
... more
Caused by: java.sql.SQLTransientConnectionException: HikariPool- - Connection is not available, request timed out after 30005ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:)
at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:)
at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$f68c05a.getConnection(<generated>)
at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:)
二、解决办法
通过异常可以发现是由于获取不到数据库连接导致,猜测是连接数不够的问题,所以修改HikariPool连接池配置,就解决了
修改前:
spring:
datasource:
hikari:
connection-test-query: SELECT FROM DUAL
connection-timeout:
maximum-pool-size:
max-lifetime:
minimum-idle:
connection-init-sql: SET NAMES utf8mb4
修改后:
spring:
datasource:
hikari:
connection-test-query: SELECT FROM DUAL
connection-timeout:
maximum-pool-size:
max-lifetime:
minimum-idle:
validation-timeout:
idle-timeout:
connection-init-sql: SET NAMES utf8mb4
【异常】Caused by: java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30005ms.的更多相关文章
- 异常:Caused by: java.sql.SQLException: Field 'cust_id' doesn't have a default value
异常: 由Java.q.L.SqLExpExt引起:字段“CuSTyID”没有默认值 Caused by: java.sql.SQLException: Field 'cust_id' doesn't ...
- Oracle异常:Caused by: java.sql.SQLException: ORA-01536: 超出表空间 '登录名' 的空间限额 (JPA保存数据)
原因: Oracle表空间为0,没有分配空间内存. 解决办法在代码框里: 1. 查看用户表空间的限额 select * from user_ts_quotas; max_bytes字段就是了 -1是代 ...
- 数据库连接异常 Caused by: java.sql.SQLException: Unknown system variable 'tx_isolation'
1.错误截图 2.错误分析 数据库的版本比连接驱动的版本高很多. 3.解决方法 因此将mysql-connector-java升级到最新版本就解决了问题. 原本我的版本是mysql-connector ...
- hibernate 出现Caused by: java.sql.SQLException: Column 'id' not found.异常
用hibernate进行映射查询时,出现Caused by: java.sql.SQLException: Column 'id' not found 异常,检查数据库表及映射都有id且已经正确映射, ...
- Caused by: java.sql.SQLException: Incorrect integer value: '' for column 'clientId' at row 41
1.错误描述 [ERROR:]2015-06-10 13:48:26,253 [异常拦截] oa.exception.ExceptionHandler org.hibernate.exception. ...
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
1.错误描述 [ERROR:]2015-05-05 16:35:50,664 [异常拦截] org.hibernate.exception.GenericJDBCException: error ex ...
- Caused by: java.sql.SQLException: Operand should contain 1 column(s)
1.错误描述 [ERROR:]2015-05-05 15:48:55,847 [异常拦截] org.hibernate.exception.DataException: error executing ...
- Caused by: java.sql.SQLException: Failed to start database 'metastore_db' with class loader org.apache.spark.sql.hive.client.IsolatedClientLoader$$anon$1@d7c365, see the next exception for details.
解决方法:https://stackoverflow.com/questions/37442910/spark-shell-startup-errors 异常: 18/01/29 19:04:27 W ...
- Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Lock wait timeout exceeded; try restarting transaction
更新的时候报 Caused by: java.sql.BatchUpdateException: Transaction error, need to rollback. errno:1205 Loc ...
随机推荐
- android studio 修改选中内容背景色,以及匹配的内容背景色
#与选中内容匹配的内容背景色Editor -> Color Scheme -> General -> Code -> Identifier under caret #选中内容前 ...
- java 集合运算
package testjavapro; import java.util.BitSet; public class testjavaa { public static void main(Strin ...
- 【牛客练习赛53】A-超越学姐爱字符串
// 题目地址:https://ac.nowcoder.com/acm/contest/1114/A /* 找规律(碰运气) n:1 = 2 n:2 = 3 n:3 = 5 n:4 = 8 ... d ...
- sublime插件开发: 文件说明
sublime插件开发 文件 .sublime-settings 设置文件 Main.sublime-menu 主菜单按钮配置文件 Side Bar.sublime-menu 侧边栏菜单文件列表,选中 ...
- Android Studio 之 ROM【3】,LiveData+ViewModel+AsyncTask+Repository+RecyclerView
教程地址:https://www.bilibili.com/video/av65180549 源码地址:https://github.com/longway777/Android-2019-Tutor ...
- Hotspot的栈
各种类型的线程他们所需要的栈的大小其实是可以通过不同的参数来控制的: java_thread的stack_size,其实就是-Xss或者-XX:ThreadStackSize的值 compiler_t ...
- kubernetes 中遇见的一些坑(持续更新)
一.官网镜像无法下载 解决方法:需要翻墙 配置docker翻墙机: cat /usr/lib/systemd/system/docker.service [Service] Environment ...
- [Gamma]Scrum Meeting#8
github 本次会议项目由PM召开,时间为6月3日晚上10点30分 时长15分钟 任务表格 人员 昨日工作 下一步工作 木鬼 撰写博客,组织例会 撰写博客,组织例会 swoip 前端显示屏幕,翻译坐 ...
- 【操作系统之十】内存分页管理与swap
一.虚拟内存电脑里内存分内存条(这里我们叫物理内存)和硬盘,内存条保存程序运行时数据,硬盘持久保存数据.那么虚拟内存是什么? 程序运行会启动一个进程,进程里有程序段.全局数据.栈和堆,这些都会加载到内 ...
- centos6.5 安装hadoop1.2.1亲测版
本篇只简单介绍安装步骤 1. 角色分配 10.11.84.4 web-crawler--1.novalocal master/slave 10.11.84.5 web-crawler--2.nova ...