我将Glassfish和Toplink与MS-SQL-Server一起使用,因此sqljdbc4.jar用于连接数据库。当数据库不可用(数据库服务器关闭)时,CPU使用率上升到100%,Glassfish继续尝试永久连接。我的日志迅速填满以下消息:
FINE: TDSChannel (ConnectionID:7) read failed:Connection reset
FINE: *** SQLException:ConnectionID:7 com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset Connection reset
FINE: com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1368)com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1355)com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1532)com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3274)com.microsoft.sqlserver.jdbc.TDSReader.nextPacket(IOBuffer.java:3227)com.microsoft.sqlserver.jdbc.TDSReader.ensurePayload(IOBuffer.java:3203)com.microsoft.sqlserver.jdbc.TDSReader.peekTokenType(IOBuffer.java:3420)com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:50)com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:39)com.microsoft.sqlserver.jdbc.SQLServerStatement.processExecuteResults(SQLServerStatement.java:1064)com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.processResponse(SQLServerPreparedStatement.java:345)com.microsoft.sqlserver.jdbc.TDSCommand.close(IOBuffer.java:4111)com.microsoft.sqlserver.jdbc.SQLServerStatement.discardLastExecutionResults(SQLServerStatement.java:99)com.microsoft.sqlserver.jdbc.SQLServerStatement.closeInternal(SQLServerStatement.java:592)com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.closeInternal(SQLServerPreparedStatement.java:170)com.microsoft.sqlserver.jdbc.SQLServerStatement.close(SQLServerStatement.java:604)com.sun.gjc.spi.ManagedConnectionFactory.isValidByTableQuery(ManagedConnectionFactory.java:397)com.sun.gjc.spi.ManagedConnectionFactory.isValid(ManagedConnectionFactory.java:297)com.sun.gjc.spi.ManagedConnectionFactory.getInvalidConnections(ManagedConnectionFactory.java:246)com.sun.enterprise.resource.AbstractConnectorAllocator.getInvalidConnections(AbstractConnectorAllocator.java:99)com.sun.enterprise.resource.AbstractResourcePool.removeInvalidResources(AbstractResourcePool.java:1535)com.sun.enterprise.resource.AbstractResourcePool.removeInvalidAndIdleResources(AbstractResourcePool.java:1515)com.sun.enterprise.resource.AbstractResourcePool.resizePool(AbstractResourcePool.java:1448)com.sun.enterprise.resource.AbstractResourcePool$Resizer.run(AbstractResourcePool.java:1610)java.util.TimerThread.mainLoop(Timer.java:512)java.util.TimerThread.run(Timer.java:462)
有没有办法为数据库连接设置重试限制,或者连接重试之间有暂停超时?
如何让Glassfish抛出异常,而不是试图永远连接?
答案 0 :(得分:0)
我们追踪到这一点,这似乎是微软在sqljdbc4.jar中的一个错误:
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=483322
答案 1 :(得分:0)
HADB版GlassFish免费提供MS SQL的DataDirect JDBC驱动程序,可以处理连接重置并关闭