Dubbo超时重试导致的数据重复插入

 以下是一个新增服务:

public void saveDept(DeptVO vo) {
        deptService.saveDept(BeanCopierUtil.copy(vo,DeptModel::new,DeptModel.class));
        try {
            Thread.sleep(15*1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
             e.printStackTrace();
        }
    }

具体实现:

@Override
    public void saveDept(DeptModel model) {
    	model.createId();
    	model.setUpdateTime(new Date());
        deptDao.insert(model);
    }

超时时间设为6秒:

	<dubbo:service interface="com.xxx.DeptProvider" ref="deptProviderImpl" timeout="6000" version="1.0" />

调用端:

 @RequestMapping(value = {"/test20.html"})
     public void t20(HttpServletResponse resp,String userCode,String abb) throws Exception {
         long start = System.currentTimeMillis();
         DeptVO vo = new DeptVO();
         vo.setDeptName("xxx测试Dubbo超时数据插入重复");
         
         deptProvider.saveDept(vo);
        long end = System.currentTimeMillis();
         
         System.out.println("+++++++++++++++++耗时:"+(end-start));
         resp.getWriter().write("+++++++++++++++++耗时:"+(end-start)+"     结果:"+JSONUtils.serializeObject(vo));

     }

数据库的记录:

 

解决办法:

在服务端,新增时,实体类的id要从调用端传入,这样id重复时会因违背主键唯一约束而插不进去。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值