以下是一个新增服务:
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重复时会因违背主键唯一约束而插不进去。