我有一个 Java Web 应用程序,它使用 Hibernate 连接到 MSSQL 2005 数据库。
由于从我的应用程序到数据库的连接并不重要,我想测试当数据库不可用时应用程序的行为。
当我停止 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.".
有谁知道如何减少应用程序的挂起时间?
谢谢
肖
最佳答案
正如您提到的,它是一个 Web 应用程序,我想您正在使用容器(Tomcat、JBoss AS,...)提供的数据源,对吧?正确的?? :-)
如果是这种情况,那么您的容器肯定有办法配置它。对于 JBoss AS,这将是“blocking-timeout-millis”。
关于java - 如何减少数据库连接失败的挂起时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11937851/