设为首页 加入收藏

TOP

为什么要拒绝使用大事务进行处理任务(二)
2017-12-18 12:36:44 】 浏览:1374
Tags:为什么 拒绝 使用 事务 进行 处理 任务
ng(jobParamBean)); recordEntity.setJobParams(JSONObject.toJSONString(cond)); recordEntity.setExecServerIp(myServerIp); recordEntity.setReqServerIp(dubboConsumerIp); recordEntity.setJobEndTime(DateUtils.convert(now, "yyyy-MM-dd HH:mm:ss.S")); Integer recordAffectNum = jobExecRecordMapper.addJobExecRecord(recordEntity); Long recordId = recordEntity.getId(); Integer realUpdateNum = 0; if(totalUpdate != null && totalUpdate > 0) { Integer pageStart = 0; Integer perPageNum = 10; String nowDateStr = DateUtils.convert(now, "yyyy-MM-dd"); //当前时间 for(int i = 0; i < totalUpdate; i += perPageNum) { pageStart = i; cond.put("pageStart", pageStart); cond.put("perPageNum", perPageNum); Integer thisAffectNum = platformAssistantBusiness.pieceUpdateBorrowStatus(cond, nowDateStr);   // 使用辅助类进行小事务的拆分 realUpdateNum += thisAffectNum; recordEntity.setCurrentAffectNum(perPageNum); recordEntity.setRealAffectNum(thisAffectNum); recordEntity.setStatus("1"); jobExecRecordMapper.updateJobExecRecord(recordEntity); } } recordEntity.setStatus("5"); recordEntity.setCurrentAffectNum(0); recordEntity.setRealAffectNum(0); String jobEndTime = DateUtils.convert(new Date(), "yyyy-MM-dd HH:mm:ss.S"); recordEntity.setJobEndTime(jobEndTime); jobExecRecordMapper.updateJobExecRecord(recordEntity); result = totalUpdate; logger.info("exit {} method, result:{}", method, result); return result; }

小事务放在另一方法中,以确保事务生效!

@Override
    @Transactional(readOnly = false, rollbackFor = Throwable.class, isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRES_NEW)
    public Integer pieceUpdateBorrowStatus(Map<String, Object> cond, String nowDateStr) {
        String shouldRepayDate = "";
        Long lateDays = 0L;
        String borrowStatus;
        Integer thisAffectNum = 0;
        List<UsersBorrowEntity> pageList1 = borrowMapper.getUsersBorrowListByMap(cond);
        for(UsersBorrowEntity borrowEntity1 : pageList1) {
            UsersBorrowEntity updateBorrowEntity = new UsersBorrowEntity();
            updateBorrowEntity.setId(borrowEntity1.getId());
            updateBorrowEntity.setUserId(borrowEntity1.getUserId());
            shouldRepayDate = borrowEntity1.getShouldRepayTime();
            lateDays = DateUtils.getDayDiff(shouldRepayDate, nowDateStr);
            if(lateDays != null && lateDays >= 0 && !"8".equals(borrowEntity1.getBorrowStatus())) {
                if(lateDays == 0) {
                    borrowStatus = "5";
                } else {
                    borrowStatus = "6";
                }
                updateBorrowEntity.setBorrowStatus(borrowStatus);
                updateBorrowEntity.setRepayStatus(CommonUtil.getRepayStatusByBorrowStatus(borrowStatus));
                updateBorrowEntity.setLateDays(lateDays.intValue());
                Integer affectNum = usersBorrowMapper.updateUsersBorrow(updateBorrowEntity);
                thisAffectNum += affectNum;
            }
        }
        return thisAffectNum;
    }

这样就保证了,执行的完整性,然后,每10个小事务就进行提交一次。从而解决锁超时问题了。

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Java String 对 null 对象的容错.. 下一篇重构大型业务型写接口 :并行处理..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目