首页 新闻 会员 周边

使用Java的lambda表达式循环插入(mybtais)数据库,发现只保存了部分数据,漏掉了一部分数据的问题

0
悬赏园豆:200 [待解决问题]

出现问题的环境:Java的web框架,Spring和mybatis,使用Java8。

描述:在使用Java8的lambda表达式进行循环插入(mybtais)数据库的时候发现,只有部分数据被插入了,还漏掉了一部分,通过输出的日志判断总共插入了119条,但实际保存了69条。我的问题是日志中已经输出了SQL,为什么没有全部保存到数据库中?

下面给出代码和日志,望各位大佬帮忙详细分析下是怎么回事,小白在此感谢!

说明:日志中所有输出的SQL都是正确的的,所有SQL可以分为两类,

一类是ForkJoinPool.commonPool-worker操作的;

另一类是org.springframework.jms.listener.DefaultMessageListenerContainer

ForkJoinPool操作的SQL都在数据库中保存了,但是DefaultMessageListenerContainer操作的SQL全都没有保存到数据库中。

 

Java代

 1 public Integer saveCheckinData(String openCheckinDataType, String startTime, String endTime, List<String> useridList) throws Exception {
 2         List<WcCheckin> list = getCheckinData(openCheckinDataType, startTime, endTime, useridList);
 3 
 4         list.parallelStream()
 5                 .filter(wcCheckin -> StringUtils.isNotBlank(wcCheckin.getExceptionType()))
 6                 .filter(wcCheckin -> StringUtils.isNotBlank(wcCheckin.getGroupname()))
 7                 .forEach(wcCheckin -> insertSelective(wcCheckin));
 8 
 9         return list.size();
10     }

 

日志截图

复制代码
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30221(Long), 10004666(String), 华中打卡(String), 0(Short), 0(String), 1554768020(Long), 集团有限公司(String), 湖南省长沙市天心区新姚南路200(String), Stark_晃_5G(String), (String), (String), ["WWCISP_0zBvIdaurkAx2a6bmUUvzunkwph3LgygxJ3ZNDeWotDBHh7ffgAYmjIh6fosuIC4ox8Qeg0uKfEcdD_qpJBcfQ"](String), 2019-04-10 03:13:12.072(Timestamp)
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30221==========
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30222(Long), 10004404(String), 上海库房(String), 0(Short), 未打卡(String), 1554771600(Long), (String), (String), (String), (String), (String), [](String), 2019-04-10 03:13:12.08(Timestamp)
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30222==========
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30223(Long), 10004404(String), 上海库房(String), 1(Short), 未打卡(String), 1554804000(Long), (String), (String), (String), (String), (String), [](String), 2019-04-10 03:13:12.082(Timestamp)
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30223==========
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30224(Long), 10004767(String), 济宁办事处725(String), 0(Short), 0(String), 1554770410(Long), 集团有限公司(String), 山东省济宁市任城区京杭路(String), 6666666666(String), (String), b8:3a:08:e1:ed:e0(String), ["WWCISP_16udLcJNc8EiVyC5eXTopxtXWd19oTxN3ER_qlnPp90bVgCJxIcgJr75N_1XIb6YU364DIOsZFTaK8rKOxdKRQ"](String), 2019-04-10 03:13:12.083(Timestamp)
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
=======插入完成30224==========
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30225(Long), 10002534(String), 西安平台(String), 0(Short), 0(String), 1554769620(Long), 集团有限公司(String), 甘肃省兰州市城关区兰新市场万国港C座906室(String), ◊œπ‚ ˝¬Î(String), (String), (String), ["WWCISP_Cct6BgZU9I3I35T1n3sbBlittUbLwSk3SbUGyhCIHBwWKATETXcxVaE51lHK_RsmBog9pfJEHTu6aVUS2HW9Jw"](String), 2019-04-10 03:13:12.073(Timestamp)
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30225==========
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[org.springframework.jms.listener.DefaultMessageListenerContainer#3-1] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30226(Long), 10004650(String), 北京办事处(String), 0(Short), 0(String), 1554770910(Long), 集团有限公司(String), 北京市海淀区中关村东路1号院10号(String), (String), (String), (String), ["WWCISP_jP_c-yfvFcZ1G2e1L2HlNI4cdJEdXGWUoZzcD4wxCNW629_n53gB2euHaBmZDxrEXq3vIpCQaMcnbsl3aoH24A"](String), 2019-04-10 03:13:12.086(Timestamp)
[ForkJoinPool.commonPool-worker-6] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30226==========
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==>  Preparing: select WC_CHECKIN_SEQ.nextval as id from dual 
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - ==> Parameters: 
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective!selectKey] - <==      Total: 1
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==>  Preparing: insert into WC_CHECKIN ( ID, USERID, GROUPNAME, CHECKIN_TYPE, EXCEPTION_TYPE, CHECKIN_TIME, LOCATION_TITLE, LOCATION_DETAIL, WIFINAME, NOTES, WIFIMAC, MEDIAIDS, CREATE_TIME ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - ==> Parameters: 30227(Long), 10004831(String), 物流-杭州(String), 1(Short), 未打卡(String), 1554804000(Long), (String), (String), (String), (String), (String), [](String), 2019-04-10 03:13:12.073(Timestamp)
[ForkJoinPool.commonPool-worker-3] DEBUG [com.thunis.wecorp.dao.inf.WcCheckinMapper.insertSelective] - <==    Updates: 1
=======插入完成30227==========
复制代码

mesen的主页 mesen | 初学一级 | 园豆:5
提问于:2019-04-16 17:10
< >
分享
所有回答(3)
0

你先执行

list.parallelStream()

.filter(wcCheckin -> StringUtils.isNotBlank(wcCheckin.getExceptionType()))

.filter(wcCheckin -> StringUtils.isNotBlank(wcCheckin.getGroupname())).count();

看一下结果

狼爷 | 园豆:1204 (小虾三级) | 2019-04-17 01:01

你好,我把生产上的代码改一下,观察今天再来回复你,希望能继续帮忙分析下。我还问了另外一个朋友,他也让我把filter去掉再试试。

这是生产环境发现的问题,这段代码每天执行一次,发生这个问题是在某一天发生,不是每天;而且我本地环境,不会发生此问题。

支持(0) 反对(0) mesen | 园豆:5 (初学一级) | 2019-04-17 09:38
0

兄弟 怎么解决的 一摸一样的问题 我还在头疼呢

一个小小的程序员 | 园豆:200 (初学一级) | 2020-03-24 10:16

 没有从根本上解决,根本不知道是哪出了问题,但是问题还是要解决,只能改代码了,改成了普通的代码。

支持(0) 反对(0) mesen | 园豆:5 (初学一级) | 2020-06-05 11:02
0

主动结帖,没有找到问题所在

mesen | 园豆:5 (初学一级) | 2020-06-05 11:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册