@Transactional(isolation = Isolation.READ_UNCOMMITTED)
public void test(int id) {
User user = userMapper.getOne(1L);
System.out.println(user.toString());
int resultStatus = userMapper.updateUser();
System.out.println(resultStatus);
if(id == 1) {
try {
Thread.sleep(20000); // 20 s
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
issue: 两次请求访问同一个方法 test,第一次请求 param=1,更新 user 表 id=1 的用户信息,然后睡眠线程 20S,在此期间,第二次请求过来,param=2,此时按照理想状态下,应该是直接查询到的 user 是修改过后未 commit 的 user,并且不会被阻塞,直接结束,但是实际情况是 User user = userMapper.getOne(1L)查询到的还是未被修改之前的 user,而且线程因为第一次请求阻塞的原因,也被阻塞了;
我在 mysql 里开启事务,然后跟新用户信息,不提交事务,然后访问这个方法的时候,是能拿到更新后未提交的数据的,是 sleep 的线程出现了问题吗;
等一个吊大的大佬;