1

I'm trying to get an exception thrown when the DB connection is closed so that a POST request can immediately return if the connection is closed. Right now Tomcat just keeps it open and gathering log data for around 25 minutes.

The way I'm testing this is with the following SQL code from Java:

WAITFOR DELAY '00:00:20';SELECT TOP(1) * FROM USER;"

I'm using the following properties in the Tomcat config:

abandonWhenPercentageFull = 0 //Close connections as soon as timed out.
removeAbandonedTimeout = 10 //Abandon connections after 10s.
removeAbandoned = true

What I'm trying to achieve is to get my Java code to throw an exception after 10s so that a closed or reset connection doesn't tie up the connection too long.

I have tried using QueryTimeoutInterceptor and also it's equivalent from Java, but that didn't seem to help. I'm using the latest SQL Server driver.

4

1 回答 1

0

好吧,如果您正在使用连接池(您应该这样做),它返回后不会关闭一段时间。我的建议是在插入数据库/缓存之前将数据返回或处理分开

于 2021-08-31T20:01:40.827 回答