[英]How to override transaction timeout value for Spring JDBCTemplate during batchUpdate
我正在调用batch batchUpdate,它通常在一个调用中发送50个以上的查询,每个更新查询都可能更新10,000条记录。 这整个过程耗时,最终会因事务超时异常而失败。 springContext.xml中定义的数据源通过@Qualifier注入到JdbcTemplate,springContext.xml中定义的事务超时适用于整个应用程序,但是在此特定事务中,我想覆盖事务超时值在调用batchUpdate方法之前。
@Qualifier("myDataSource")
@Autowired
public void setDataSource(DataSource ds) {
this.jdbc = new JdbcTemplate(ds);
jdbc.setFetchSize(10000);
jdbc.setQueryTimeout(0); // zero means there is no limit
}
//I want to set custom transaction timeout before calling this from some other methods.
jdbc.batchUpdate(queries.toArray(new String[0]));
使用@Transactional
批注指定超时。
@org.springframework.transaction.annotation.Transactional(timeout = 123) // 123 sec
这是参考文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.