我们正在针对DB2数据库运行Spring-Batch作业。在本地方案中在Eclipse中运行时,单个事务需要更长时间并且经常超时,但例外情况如下:
2016-10-26 14:48:07,685 [main] ERROR org.springframework.batch.core.step.tasklet.TaskletStep - JobRepository failure forcing exit with unknown status
org.springframework.transaction.TransactionTimedOutException: Transaction timed out: deadline was Wed Oct 26 14:47:25 EDT 2016
at org.springframework.transaction.support.ResourceHolderSupport.checkTransactionTimeout(ResourceHolderSupport.java:141)
at org.springframework.transaction.support.ResourceHolderSupport.getTimeToLiveInMillis(ResourceHolderSupport.java:130)
at org.springframework.transaction.support.ResourceHolderSupport.getTimeToLiveInSeconds(ResourceHolderSupport.java:114)
at org.springframework.jdbc.datasource.DataSourceUtils.applyTimeout(DataSourceUtils.java:275)
at org.springframework.jdbc.core.JdbcTemplate.applyStatementSettings(JdbcTemplate.java:1222)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:581)
我可以提供完整的堆栈跟踪,但它非常大。我们使用以下组件: - Spring 3.0.7(无法升级) - org.springframework.jdbc.datasource.DriverManagerDataSource - MyBatis 3.1.1 - DB2
我一直试图弄清楚如何增加Spring事务管理器和/或数据源的超时,但我只找到一个使用Spring tx的引用:来自Spring Docs第16章的建议:
<tx:advice id="defaultTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" timeout="360"/>
</tx:attributes>
</tx:advice>
但这没有做任何事,这个问题仍然存在。我可以尝试其他任何设置吗?在数据源和/或MyBatis中?
我在DB2 JDBC属性上找不到任何东西。 org.springframework.jdbc.datasource.DriverManagerDataSource上没有任何内容。
Spring XML配置是:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${datasource.jdbcDriver}" />
<property name="url" value="${datasource.databaseUrl}" />
<property name="username" value="${datasource.username}" />
<property name="password" value="${password:datasource}" />
<property name="properties">
<props>
<prop key="oracle.jdbc.ReadTimeout">5000</prop>
</props>
</property>
</bean>
<!-- ================================================================== -->
<!-- MyBatis Mapper Configuration -->
<!-- ================================================================== -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="defaultTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" timeout="360"/>
</tx:attributes>
</tx:advice>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
tia,adym