一、异常出现的场景

  一次线上订单历史数据字段刷新操作,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. windows下socket编程实现client和server双向通信

    服务端代码server.c // server.cpp : Defines the entry point for the console application. // #include <s ...

  2. C函数之readlink

    函数原型; #include<unistd.h> ssize_t readlink(const char *path, char *buf, size_t bufsiz); 函数说明: r ...

  3. nRF51822 看门狗和OTA (无线升级功能)的尴尬笔记

    很久没有记笔记了.今天要记点东西,不然以后又忘记了. 随着时代的发展,现在的SDK已经是13.0了.蓝牙5.0也就来了.废话就少说了,记笔记吧. 两年前搞过nRF51822 的无线升级功能,那时候用的 ...

  4. mapreduce 函数入门 一

    MapReduce 程序的业务编码分为两个大部分,一部分配置程序的运行信息,一部分 编写该 MapReduce 程序的业务逻辑,并且业务逻辑的 map 阶段和 reduce 阶段的代码分别继 承 Ma ...

  5. wraps补充

    ''' wraps: (了解) 是一个修复工具,修复的是被装饰对象的空间. from functools import wraps ''' from functools import wraps de ...

  6. CentOS下安装php 5.6.19

    # php安装包下载wget https://www.php.net/distributions/php-5.6.19.tar.bz2# 解压bunzip2 php-5.6.19.tar.bz2tar ...

  7. jmeter 生成不重复的手机号

    String account = "${__time(yyyyMMdd,)}"+UUID.randomUUID().toString().split("-")[ ...

  8. python+requests+unittest 接口ddt测试

    以数据驱动的形式,将用例维护在py文件中 源码分析: 变量定义 publicParameters.py """ 公共参数 , 按照各公司实情,自行编写 "&qu ...

  9. php 无限极分类,根据父级 找子级

    /** * @param $data 数据(二维数组格式) * @param $adminId 管理员ID * @param $pid 权限的上级ID * @param int $level 水平变量 ...

  10. WPF USB设备采集开源工具介绍

    最近项目需要需要试试采集电脑USB 设备信息 找到了 开源 示例 代码非常好  公共库也很友好  可能知名度太低   才4star https://github.com/vurdalakov/usbd ...