Spring 事务超时 [英] Spring Transactional TimeOut
问题描述
我正在尝试使用 spring @Transactional
注释和 timeout
参数.我基本上用放置一些 Thread.sleep()
代码来测试代码.然后我得到了我预期的超时异常.另外,当数据库操作花费的时间超过我的超时时间时,我想获得超时异常.我使用 for update select 语句锁定数据库表中的记录.我尝试更新该记录.但是程序等待什么都不做.这是我的示例代码.
I am trying to use spring @Transactional
annotation and timeout
parameter. I basically test the code with put some Thread.sleep()
codes. Then i get timeout exception as i expected. Also i want to get timeout exception when database operations take longer than my timeout period. I lock a record in a table in my database with for update select statement. I try to update that record. But program wait and do nothing. Here my sample code.
@Transactional(rollbackFor = Exception.class, timeout=5)
public void executeService(List<sendData> list) throws Exception{
List<sendData> newList = gDAO.updateSentList(list);
}
在这种情况下,程序应该抛出超时异常.我该如何解决?
In this case the program should throw timeout exception. How can i fix it?
推荐答案
我在应用程序上下文中使用 oracle.jdbc.ReadTimeout=60000
解决了我的问题.@Transactional
注释对 jdbc 读取超时异常不起作用.
I solved my problem using oracle.jdbc.ReadTimeout=60000
on application context. @Transactional
annotation do not work on jdbc read timeout exception.
这篇关于Spring 事务超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!