在使用@Transactional
注释的方法中,LOCK TABLE
语句应该在try
block 内部还是之前执行?
选项 1:
jdbcTemplate.execute(SQL_LOCK);
try {
//Some work
} finally {
jdbcTemplate.execute(SQL_UNLOCK);
}
选项 2:
try {
jdbcTemplate.execute(SQL_LOCK);
//Some work
} finally {
jdbcTemplate.execute(SQL_UNLOCK);
}
谢谢, 米凯尔
最佳答案
选项 2 似乎更可取,因为即使在执行 SQL_LOCK
期间抛出异常,它也能保证执行 SQL_UNLOCK
语句。
关于java - LOCK TABLE 和 try-catch block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23535285/