突发奇想:使用多线程调用多个方法提高处理速度以及验证单个事务内使用多线程将导致事务失效与异常捕获失效。

一、起因

今天突发奇想,想着我一个方法内调用了多个方法,且这几个方法没有相互的影响关系,那我是不是可以通过使用多线程来提高系统的响应速度呢。

二、未加事务原始代码

save方法

public boolean save(StoreOrganization entity){
        String id = idGeneratorService.queryGeneratorId();
            if (id == null || id == "") {
                throw new ServiceException(CommonError.error("新增失败"));
            }
        Response responseP = platformService.getById(entity.getPlatid());
            if(responseP.getCode() != 200 || responseP.getData() == null){
                throw new ServiceException(CommonError.error("新增失败,平台信息有误"));
            }
        Response responseS=storeService.getById(entity.getStoreId());
            if(responseS.getCode() != 200 || responseS.getData() == null){
                   throw new ServiceException(CommonError.error("新增失败,店铺信息有误"));
               }
        entity.setId(Long.parseLong(id));
        entity.setCreatedtime(LocalDateTime.now());
        int row = baseMapper.insert(entity);
        if (row <= 0) {
            throw new ServiceException(CommonError.error("新增失败"));
        }
        return true;
    }

调用方法解释

idGeneratorService.queryGeneratorId():生成唯一ID服务。
platformService.getById(entity.getPlatid()):获取平台ID。
storeService.getById(entity.getStoreId()):

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值