【异常】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 ...
随机推荐
- PATA1031 Hello World for U
参考代码: #include <cstdio> #include <cstring> int main() { char str[100], ans[40][40]; scan ...
- vue动态添加路由,跳转页面时,页面报错路由重复:vue-router.esm.js?8c4f:16 [vue-router] Duplicate named routes definition: { name: "Login", path: "/login" }
之前用了一个vue-element-admin做了一个小项目,里面用到了动态添加路由,动态展示侧边栏, 当我切换页面时,控制台总是警告提示路由重复,连续跳转几次页面后,控制台就被这些警告占满了, 于是 ...
- 关于getClass(),Object.class,getClassLoader的理解
1.对Class类的理解:Class类包含了类的信息,如构造方法.方法.属性,可用于反射.以下是所有方法 2.获取Class类对象的几种方法: Test test = new Test(); (1). ...
- V8 引擎如何进行垃圾内存的回收?
JS 语言不像 C/C++, 让程序员自己去开辟或者释放内存,而是类似Java,采用自己的一套垃圾回收算法进行自动的内存管理.作为一名资深的前端工程师,对于JS内存回收的机制是需要非常清楚, 以便于在 ...
- 招聘.net高级工程师
1. 本科及以上学历(必须): 2. 精通.net框架和常见web框架,精通常见设计模式并熟练应用. 3. 扎实的技术功底,有良好的数据结构和算法基础,深入理解面向对象编程思想, 熟悉面向对象的基本设 ...
- Python学习教程(十)精选 TOP45 值得学习的Python项目
精选 TOP45 值得学习的Python项目 [导读]热门资源博客 Mybridge AI 比较了 18000 个关于 Python 的项目,并从中精选出 45 个最具竞争力的项目.我们进行了翻译,在 ...
- 25个led灯新玩法
Microbit板子的25个led灯,是5X5的阵列,led(lights emitting diodes)中文叫发光二极管,有单向导电性,还发光,有各种颜色的,红,蓝,黄等等.mPython可以让你 ...
- Chartjs 简单使用 ------ 制作sin cos 折线图
Chart.js 一款简单干净的图表工具,基于html5 的Javascript. 可以用来制做条形,扇形,折线,混合等等的强大工具 图表要放在html 的 cancas 标签中 <canv ...
- 责任链(ChainOfResponsibility)模式
在责任链模式里,很多对象由每一个对象对其下家的引用而连接起来形成一条链.请求在这个链上传递,直到链上的某一个对象决定处理此请求.发出请求的客户端并不知道链上的哪一个对象,这使得系统可以在不影响客户端的 ...
- Python 3 + Selenium 3 实现汉堡王客户调查提交
用Python 3 + Selenium 3实现汉堡王客户调查的自动填写,可以用来作为 python selenium的入门学习实现脚本,列举了几个比较不太好弄的知识点. 上代码: from sele ...