问题原由

最近使用 quartz 写了一个定时任务,这个定时任务主要是给会员增加类似积分的东西,并且要保存积分增加记录,每天凌晨4点钟执行,但是会有些时候会出现很多会员的积分并没有增加,查了一下日志,发现 Druid 抛出了 abandon connection, open stackTrace,查看了一下报错的代码行,是在保存积分增加记录的时候抛出的异常,而且是等了30分钟才抛出的,也就是说,4点开始执行,然后4点半就抛异常了,导致用户的积分没有增加。

表结构

-- 用户会员信息表

create table client_vip_user_info

(

id varchar(36) not null comment '主键'primary key,

user_id varchar(36) null comment '用户编号',

had_stays int default 0 not null comment '积分',

create_time datetime null comment '创建时间(成为会员的时间)',

update_time datetime null comment '更新时间',

deadline datetime null comment '本期截止时间',

min_vip_level varchar(36) null comment '会员最低等级',

source varchar(20) null comment '注册途径'

)comment '用户会员信息表';

-- 会员积分记录表

create table client_vip_stays_log

(

id varchar(36) not null comment '主键' primary key,

userid varchar(36) null comment '用户编号',

type varchar(36) null comment '类型',

oldvalue int null comment '老数据',

incomevalue int null comment '新添加的数据',

value int null comment '当前数据',

createtime timestamp null comment '创建时间'

)comment '会员积分操作日志';

相关代码

//定时器

public void execute(JobExecutionContext context) throws JobExecutionException {

//加载bean

LiveUserService liveUserService = (LiveUserService) AppContext.getSpringBean("liveUserService");

UserService clientUserService = (UserService) AppContext.getSpringBean("clientUserService");

VIPLevelService vipLevelService = (VIPLevelService) AppContext.getSpringBean("vipLevelService");

VipUserInfoService vipUserInfoService = (VipUserInfoService) AppContext.getSpringBean("vipUserInfoService");

VIPStaysLogService vipStaysLogService = (VIPStaysLogService) AppContext.getSpringBean("vipStaysLogService");

OrderService orderService = (OrderService) AppContext.getSpringBean("orderService");

try {

//获取前一天的日期

String yesterday = DateUtil.getYesterdayDate();

//获取当前日期前一天的入住人

List> list = liveUserService.getLiveUsers(yesterday);

User user = null;

Order order = null;

for (Map map : list) {

user = clientUserService.findByPhone(map.get("PHONE").toString(), map.get("phoneareacode").toString());

if (null != user) {

VIPLevel vipLevel = vipLevelService.getByUserId(user.getUserID());

//是会员才会进行操作

if (null != vipLevel) {

//用户会员信息

VipUserInfo vipUserInfo = vipUserInfoService.getByUserId(user.getUserID());

int oldStays = vipUserInfo.getHadStays();

int newStays = oldStays + 1;

//间夜数变更日志

VipStaysLog vipStaysLog = new VipStaysLog();

vipStaysLog.setCreateTime(new Date());

vipStaysLog.setId(UuidUtil.get32UUID());

vipStaysLog.setOldValue(oldStays);

vipStaysLog.setIncomeValue(1);

vipStaysLog.setValue(newStays);

vipStaysLog.setUserId(user.getUserID());

vipStaysLog.setType("入住新增");

vipStaysLogService.save(vipStaysLog); //就是这一行抛出的异常

//省略代码

vipUserInfoService.update(vipUserInfo);

}

}

}

} catch (Exception e) {

LOGGER.error("-------------------error");

e.printStackTrace();

}

}

//mybatis

`client_vip_stays_log`

`id` ,

`userid` ,

`type` ,

`oldvalue` ,

`incomevalue` ,

`value` ,

`createtime`

#{id} ,

#{userId} ,

#{type} ,

#{oldValue} ,

#{incomeValue} ,

#{value} ,

#{createTime}

INSERT INTO

(

) VALUES (

)

相关配置

// 数据源配置

url:jdbc:mysql://localhost:3306/leyizhu?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8

driverClassName:com.mysql.jdbc.Driver

username:root

password:123456

filters:stat

maxActive:20

initialSize:1

maxWait:60000

minIdle:10

maxIdle:15

timeBetweenEvictionRunsMillis:60000

minEvictableIdleTimeMillis:300000

validationQuery:SELECT 'x'

testWhileIdle:true

testOnBorrow:false

testOnReturn:false

maxOpenPreparedStatements:20

removeAbandoned:true

removeAbandonedTimeout:1800

logAbandoned:true

环境配置

应用服务器

CPU: 2核

内存: 16 GB

实例类型: I/O优化

操作系统: Aliyun Linux 17.1 64位

独立数据库服务器

规格族:通用型 数据库类型:MySQL 5.6 CPU:4 核

数据库内存:8192MB 最大IOPS:5000 最大连接数:2000

可维护时间段:02:00-06:00 实例规格:rds.mysql.s3.large

错误日志

目前我检查了代码很多遍,都没有发现代码哪里有问题,同事也没有看出来,目前已知的是为什么30分钟后才抛异常,是因为 removeAbandonedTimeout 设置的就是30分钟。如果主动获取连接,30分钟没有主动释放掉,druid就会自动释放掉,也就是说,代码停止了30分钟。

abandon_mysql_使用Druid报错abandon connection, open stackTrace相关推荐

  1. com.alibaba.druid.pool.DruidDataSource - abandon connection, open stackTrace

    错误: com.alibaba.druid.pool.DruidDataSource - abandon connection, open stackTrace 原因: 连接池为了防止程序从池里取得连 ...

  2. ERROR com.alibaba.druid.pool.DruidDataSource - abandon connection, open stackTrace: 已解决

    错误日志: 2020-07-13 15:37:58,545 [Druid-ConnectionPool-Destroy-2092318840] ERROR com.alibaba.druid.pool ...

  3. 程序执行报错Missing Connection or ConnectionString 解决方法

    程序执行报错Missing Connection or ConnectionString 解决方法 参考文章: (1)程序执行报错Missing Connection or ConnectionStr ...

  4. 数据库连接报错提示connection is being used

    数据库连接报错:connection is being used 解决办法: 1.在已经保存的连接上上编辑,测试连接成功,但是点击连接就会一直提示 connection is being used 2 ...

  5. 【Exception】Navicat连接Oracle闪退 Navicat连接Oracle 报错:connection to server failed,probable Oracle Net admi

    [Exception]Navicat连接Oracle闪退 Navicat连接Oracle 报错:connection to server failed,probable Oracle Net admi ...

  6. 03-Redis客户端连接Redis服务器(redis.conf 文件配置没有生效导致redis运行报错Error: Connection reset by peer)

    参考此链接配置 redis.conf,然后本文章才能继续操作 EditPlus连接Centos7修改Redis配置文件(建议FinalShell修改更加方便)https://blog.csdn.net ...

  7. Druid连接池一个设置引发的血案【abandon connection, open stackTrace】

    2019独角兽企业重金招聘Python工程师标准>>> 今天在一台配置很低的机器上运行批量更新的程序~~~ 大概跑了三十分钟~~~这配置~~~这程序~~~ 然后华丽丽的报异常了~~~ ...

  8. 【错误记录】Android Studio 编译报错 ( Error:Connection timed out: connect | 更新配置依赖仓库方式 )

    文章目录 一.报错信息 二.解决方案 一.报错信息 编译 VirtualAppEx 源码时 , 报如下错误 : Gradle 'VirtualAppEx-master' project refresh ...

  9. ES报错:Connection reset by peer 解决经历

    http://nicethemes.cn/news/txtlist_i28391v.html 这次来分享一下ES报错:java.io.IOException: Connection reset by ...

  10. CentOS 7.1 Bridge启用STP报错Master connection not found or invalid

    今天在公司测试Linux bridge搭建,为了使内部docker容器的网络能够不经过2层封装转发对外公布,顾试用一下bridge功能,结果碰到报错:"Bringing up interfa ...

最新文章

  1. FW : 关于光棍节
  2. 新建并保存一个空的Excel
  3. android内存不足,Android OutOfMemoryError:内存不足问题的排查与解决
  4. falsk-sqlalchemy 连接数据库出现 No module named ‘MySQLdb‘(笔记自用)
  5. Python中的函数递归
  6. 【转】2010全球最值得模仿的230个网站
  7. 这里有一份面筋请查收(八)
  8. 简答面向数据报,面向字节流
  9. 七台河计算机网络工程专业,网络工程本科专业介绍
  10. 实战!轻松搭建图像分类 AI 服务
  11. gcc2.95.3安装过程
  12. Linux:Vim的安装与配置
  13. Swoole Framework 入门教程(1)
  14. OpenGL 概念整理
  15. 处理在SBS2003上安装WSUS失败的情况
  16. 2021年9月电子学会Python等级考试试卷(四级)考题解析
  17. 《幽途无人葬》游戏指南
  18. PHP读取HTML生成doc
  19. ArcEngine 入门教程-控件初体验
  20. 螺栓、螺柱、螺钉的分类

热门文章

  1. python常用语音识别库_干货收藏 | Python语音识别终极指南
  2. 【C++】黑白矩阵(美团)
  3. 【交易架构day9】阿里交易系统演进之路
  4. videojs播放器插件使用详解
  5. DCDC和LDO的区别
  6. 小米路由器4C刷机(以OpenWrt为例)
  7. msg1500说明书_瑞斯康达MSG1500 路由 刷机 保姆级教程
  8. 工作之余,别忘了生活。
  9. 电商数据分析与数据化运营
  10. Linux编程基础之Makefile的使用