一、异常出现的场景

  一次线上订单历史数据字段刷新操作,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.的更多相关文章

  1. 异常: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 ...

  2. Oracle异常:Caused by: java.sql.SQLException: ORA-01536: 超出表空间 '登录名' 的空间限额 (JPA保存数据)

    原因: Oracle表空间为0,没有分配空间内存. 解决办法在代码框里: 1. 查看用户表空间的限额 select * from user_ts_quotas; max_bytes字段就是了 -1是代 ...

  3. 数据库连接异常 Caused by: java.sql.SQLException: Unknown system variable 'tx_isolation'

    1.错误截图 2.错误分析 数据库的版本比连接驱动的版本高很多. 3.解决方法 因此将mysql-connector-java升级到最新版本就解决了问题. 原本我的版本是mysql-connector ...

  4. hibernate 出现Caused by: java.sql.SQLException: Column 'id' not found.异常

    用hibernate进行映射查询时,出现Caused by: java.sql.SQLException: Column 'id' not found 异常,检查数据库表及映射都有id且已经正确映射, ...

  5. 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. ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 通过不断迭代,编写<通过中缀表达式,构造表达式树>的代码

    今天要练习的算法是通过中缀表达式生成表达式树.中缀.前缀.后缀表达式的概念就不赘述了,学习链接:中缀.前缀.后缀表达式. 参考代码学习链接:表达式树—中缀表达式转换成后缀表达式(一). [迭代 ①]: ...

  2. C语言实现聊天室软件

    /* common.h */ /*服务器端口信息*/ #define PORTLINK ".charport" /*缓存限制*/ #define MAXNAMELEN 256 #d ...

  3. [转]Jumpserve跳板机的生产环境应用

    Jumpserver是国内一款开源的轻便的跳板机系统,他们的官网:http://www.jumpserver.org/ 使用这款软件意在提高公司内部登录生产环境服务器的便捷性,权限分配细化,以及后台管 ...

  4. Java 并发系列之五:java 锁

    1. Lock接口 2. 队列同步器AQS 3. 重入锁 ReentrantLock 4. 读写锁 ReentrantReadWriteLock 5. LockSupport工具 6. Conditi ...

  5. 码医自学法V2.2(附名老中医)

    这段时间经常有网友微信公众号问我怎么入门'中医' 我贴下我自己的学习方法(仅供参考) 基础回顾:https://www.cnblogs.com/dunitian/p/7483038.html PS:自 ...

  6. storm单机运行报错 ERROR backtype.storm.daemon.executor -

    单机本地运行storm报错: 错误如下: java.lang.NullPointerException: null at test2.Spot2.nextTuple(Spot2.java:) ~[cl ...

  7. [转帖]分布式一致性协议介绍(Paxos、Raft)

    分布式一致性协议介绍(Paxos.Raft) https://www.cnblogs.com/hugb/p/8955505.html  两阶段提交 Two-phase Commit(2PC):保证一个 ...

  8. drf面试题及总结

    drf面试题及总结 1.什么是前后端分离 2.什么是restful规范 3.模拟浏览器进行发送请求的工具 4.查找模板的顺序 5.什么是drf组件 6.drf组件提供的功能 7.drf继承过哪些视图类 ...

  9. Centos Docker 安装 Apache Guacamole

    经常在ubuntu上折腾,偶尔在centos来也来玩一把吧 1.安装DOCKER cd /etc/yum.repos.d wget https://download.docker.com/linux/ ...

  10. [CF24A]Ring road(2019-11-15考试)

    题目大意 给你一个\(n\)个点的环,每条边有方向,改变第\(i\)条边的方向代价为\(w_i\),问将其改为强连通图的最小代价.\(n\leqslant100\) 题解 求出把边全部改为顺时针和全部 ...