我有一個使用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.".
有誰知道我可以減少應用程序的暫停時間?
感謝
肖
您的驅動程序應該支持類似'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
我認爲這會和連接超時有所不同。 – shawsy 2012-08-14 08:05:03