如何在Spring DriverManagerDataSource上设置超时 [英] How can I set a timeout on spring DriverManagerDataSource
本文介绍了如何在Spring DriverManagerDataSource上设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在使用Spring框架(版本2.5)中的DriverManagerDataSource
来池化与Oracle的连接.但是,似乎这些连接没有定义任何超时-昨天,紧急数据库重新启动后,我们在数据库连接内部读取的套接字上挂了一个线程.如何设置超时时间(例如10分钟),以便下次引发异常?
We are using DriverManagerDataSource
from the Spring framework (version 2.5) to pool connections to Oracle. However, it seems that these connections don't have any timeout defined - yesterday, after emergency database restart, we had a thread hanging on a socket read inside the database connection. How can I set the timeout, to say 10 mins, so that it raises an exception next time?
推荐答案
我最终通过以下方式在Spring上下文中更改了bean:
I ended up changing the bean in the Spring context in the following way:
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" autowire="no">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="connectionProperties">
<props>
<prop key="oracle.net.READ_TIMEOUT">60000</prop>
</props>
</property>
</bean>
我不知道它是否有效.
这篇关于如何在Spring DriverManagerDataSource上设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文