一、异常出现的场景

  一次线上订单历史数据字段刷新操作,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. Linux stty命令

    stty是linux下改变和打印终端设置的常用命令. 一.参数: 1.打印终端行设置 -a,--all   以人可读的方式打印所有当前设置:-a参数比单独的stty命令输出的终端信息更详细 -g,-- ...

  2. Log4j之HelloWorld

    在编写项目的时候,我们一般都会用到日志记录,方便出错查找原因.首先我们需要了解什么是Log4j 1.使用maven建立工程,在pom.xml中加入如下: <dependency> < ...

  3. Salesforce LWC学习(八) Look Up组件实现

    本篇参考https://www.salesforcelwc.in/2019/10/lookup-in-lwc.html,感谢前人种树. 我们做lightning的时候经常会遇到Look up 或者MD ...

  4. prometheus自定义监控指标——入门

    grafana结合prometheus提供了大量的模板,虽然这些模板几乎监控到了常见的监控指标,但是有些特殊的指标还是没能提供(也可能是我没找到指标名称).受zabbix的影响,自然而然想到了自定义监 ...

  5. cad.net 合并图层错误 ctrl+u出错 !dbenti.cpp@3310:eWasErased错误

    (左边这段代码的两个事务是单独的事务,没有被另一个大的事务包裹)                                                                    ...

  6. Spring Cloud config之三:config-server因为server端和client端的健康检查导致服务超时阻塞问题

    springcloud线上一个问题,当config-server连不上git时,微服务集群慢慢的都挂掉. 在入口层增加了日志跟踪问题: org.springframework.cloud.config ...

  7. Application.mk文件官方使用说明

    本文档介绍了 ndk-build 所使用的 Application.mk 编译文件. 我们建议先阅读概念页面,然后再阅读本页面. 概览 Application.mk 指定了 ndk-build 的项目 ...

  8. 【题解】Luogu P2447 [SDOI2010]外星千足虫

    原题传送门 根据题意,题目给的每个操作就相当于异或上选中的那几只虫子的足数(mod 2)等于0/1 这是一个异或方程组,珂以用高斯消元解出每个虫子的足数(mod 2).所需最小次数或判断有多解 但是看 ...

  9. k8s-Node(节点)

    k8s-Node(节点) Node(节点)是k8s集群中相对于Master而言的工作主机.Node可以是一台物理主机,也可以是一台虚拟机(VM).在每个Node上运行用于启动和管理Pid的服务Kube ...

  10. Github Markdown 图片如何并排显示

    Github Markdown 图片如何并排显示   要一张图片接着一张图片的写,中间不能有换行.如果换行的话则图片也换行 正确的写法: ![描述](图片链接)![描述](图片链接)![描述](图片链 ...