2012-08-13 79 views
1

我有一个使用Hibernate连接到MSSQL 2005数据库的java web应用程序。如何减少数据库连接失败的挂起时间

由于从我的应用程序连接到数据库并不重要,我想测试当数据库不可用时应用程序的行为。

当我停止SQL服务并运行在数据库上运行查询的Web应用程序的一部分时,我的应用程序挂起大约30秒,然后继续正常运行。

正如预期的那样在日志中的错误是:

2012-08-13 16:33:04,974 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: 08S01 
2012-08-13 16:33:04,974 ERROR [JDBCExceptionReporter] The TCP/IP connection to the host bonnie.uk, port 1433 has failed. Error: "Connection refused. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.". 

有谁知道我可以减少应用程序的暂停时间?

感谢

+2

您的驱动程序应该支持类似'ConnectionTimeout'属性的东西。我不太熟悉JDBC或你的框架的其他部分,但[它看起来像它通常支持](http://publib.boulder.ibm.com/infocenter/soliddb/v6r3/index.jsp ?主题=/com.ibm.swg.im.soliddb.programmer.doc/DOC/s0005099.connection.timeout.in.jdbc.html)。顺便说一下,第二个Google打到了“JDBC连接超时”。 – 2012-08-13 15:58:58

+0

我认为这会和连接超时有所不同。 – shawsy 2012-08-14 08:05:03

回答

1

正如你所说,这是一个Web应用程序,我想你使用的是由你的容器(Tomcat时,JBoss AS中,...)提供一个数据源,对不对?对?? :-)

如果是这样的话,那么你的容器肯定有办法来配置它。对于JBoss AS来说,这将是“blocking-timeout-millis”。

+0

感谢您的回复。是的,我正在使用Geronimo应用程序服务器。这也有类似的特性,称为阻塞超时,默认为5秒。尽管这似乎没有任何影响。我已经尝试减少到​​0.5秒 – shawsy 2012-08-14 08:02:49