Esempio n. 1
0
 // 事务传播为Propagation.REQUIRES_NEW
 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW)
 public void read() throws Exception {
   User user = userMapper.findByUserName("first");
   System.out.println(
       String.format(
           "当前readTran线程%s,读取用户信息完成,用户%s,时间戳%tc", Thread.currentThread(), user, new Date()));
 }
Esempio n. 2
0
 @Transactional(isolation = Isolation.SERIALIZABLE, propagation = Propagation.REQUIRES_NEW)
 public void readBatch() throws Exception {
   List<User> users1 = userMapper.findByAge("10");
   System.out.println(
       String.format(
           "当前readBatch线程%s,读取用户信息,用户%s,时间戳%tc",
           Thread.currentThread(), ArrayUtils.toString(users1.toArray()), new Date()));
   try {
     TimeUnit.SECONDS.sleep(5);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   List<User> users2 = userMapper.findByAge("10");
   System.out.println(
       String.format(
           "当前readBatch线程%s,读取用户信息完成,用户%s,时间戳%tc",
           Thread.currentThread(), ArrayUtils.toString(users2.toArray()), new Date()));
 }
Esempio n. 3
0
 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW)
 public void write() throws Exception {
   User user = userMapper.findByUserName("first");
   System.out.println(
       String.format("当前write线程%s,更新用户信息,用户%s,时间戳%tc", Thread.currentThread(), user, new Date()));
   user.setAge("100");
   userMapper.updateUserById(user);
   System.out.println(
       String.format(
           "当前write线程%s,更新用户信息完成,用户%s,时间戳%tc", Thread.currentThread(), user, new Date()));
   try {
     TimeUnit.SECONDS.sleep(2);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   user = userMapper.findByUserName("first");
   System.out.println(
       String.format("当前write线程%s,更新用户信息,用户%s,时间戳%tc", Thread.currentThread(), user, new Date()));
 }
Esempio n. 4
0
 // 事务传播为Propagation.REQUIRES_NEW
 @Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW)
 public void readTran() throws Exception {
   System.out.println(
       String.format("当前readTran线程%s,读取用户信息,时间戳%tc", Thread.currentThread(), new Date()));
   try {
     TimeUnit.SECONDS.sleep(5);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   User user = userMapper.findByUserName("first");
   System.out.println(
       String.format(
           "当前readTran线程%s,读取用户信息完成,用户%s,时间戳%tc", Thread.currentThread(), user, new Date()));
 }