我在应用程序中将Spring Boot 2与jdbcTemplate一起使用。我使用了Informix。我正在测试并发性,我希望我的应用程序等待一段时间查询尝试更新被锁定的行。这个时间可以在informix中设置“设置锁定模式以等待20”。但是我正在春季jdbcTemplate中寻找一种方法,或者在春季寻找某种东西。
我尝试在jdbcTemplate.setQueryTimeout(60);
中设置超时,但是没有用。
欢迎提出任何想法。
jdbcTemplate.setQueryTimeout(60);
cachedExecutor.execute(() -> jdbcTemplate.update(updatenIndoPeriodeInLfa()) );
cachedExecutor.execute(() -> jdbcTemplate.update(updatenAfroPeriodeInLfa()) );
private String updatenIndoPeriodeInLfa(){
String query = "UPDATE lfa " +
"set indomonth = 09, indoyear = 2019 , indotype = indo " +
"WHERE lfa.id in (select id " +
" from procindo " +
" where month = 09 and" +
" year = 2019 and" +
" type= indo );";
return query;
}
private String updatenAfroPeriodeInLfa(){
String query = "UPDATE lfa " +
"set afromonth = 09, afroyear = 2019 , afrotype = indo " +
"WHERE lfa.id in (select id " +
" from procafro " +
" where month = 09 and" +
" year = 2019 and" +
" type= afro );";
return query;
}
在阅读了Informix文档之后,我遇到了这个问题:
应用程序可以使用此属性来覆盖用于访问锁定的行或表的默认服务器进程。获取IFX_LOCK_MODE_WAIT变量的值,该值特定于Informix。默认值为0(不等待锁定)。如果已显式设置该值,则它将返回设置值。返回:整数。设置IFX_LOCK_MODE_WAIT变量的值,该值特定于Informix。可能的值:
- 1等待直到锁被释放。
0不要等待,结束操作,然后返回错误。
NN等待nn秒以释放锁定。
然后在我的应用程序数据源配置中,如下所示传递了此属性:
@Bean(name = "informixDataSource")
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.informix.jdbc.IfxDriver");
Properties properties = new Properties();
properties.put("IFX_LOCK_MODE_WAIT", "60");
dataSource.setConnectionProperties(properties);
dataSource.setUrl(jdbc.getUrl());
dataSource.setUsername(jdbc.getUser());
dataSource.setPassword(jdbc.getPassword());
return dataSource;
}