1、先看代码
1.1、spring-config.xml
1.2、测试用例
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring-config.xml")
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = false)
@Transactional(timeout = 2)
public class Timeout1Test {
@Autowired
private DataSource ds;
@Test
public void testTimeout() throws InterruptedException {
System.out.println(System.currentTimeMillis());
JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
jdbcTemplate.execute(" update test set name = name || '1'");
System.out.println(System.currentTimeMillis());
Thread.sleep(3000L);
}
}
我设置事务超时时间是2秒;但我事务肯定执行3秒以上;为什么没有起作用呢? 这其实是对Spring实现的事务超时的错误认识。那首先