从连接池获得连接,循环数据怎么总报异常
答案:2 悬赏:80 手机版
解决时间 2021-04-28 06:17
- 提问者网友:精神病院里
- 2021-04-27 07:16
从连接池获得连接,循环数据怎么总报异常
最佳答案
- 五星知识达人网友:一把行者刀
- 2021-02-26 04:07
上使用DBCP时,因为网络闪断、数据库重启、授权错误,在获取连接出现异常时,就可能导致连接数持续增多,配置以下参数可以进行补救:
datasource.removeAbandoned=true
datasource.removeAbandonedTimeout=120
datasource.logAbandoned=true
datasource.removeAbandoned=true
datasource.removeAbandonedTimeout=120
datasource.logAbandoned=true
全部回答
- 1楼网友:琴狂剑也妄
- 2020-10-14 10:48
上使用dbcp时,因为网络闪断、数据库重启、授权错误,在获取连接出现异常时,就可能导致连接数持续增多,配置以下参数可以进行补救:
datasource.removeabandoned=true
datasource.removeabandonedtimeout=120
datasource.logabandoned=true
datasource.removeabandoned=true
flags to remove abandoned connections if they exceed the removeabandonedtimout.
a connection is considered abandoned and eligible for removal if it has not been used for longer than removeabandonedtimeout.
creating a statement, preparedstatement or callablestatement or using one of these to execute a query (using one of the execute methods) resets the lastused property of the parent connection.
setting one or both of these to true can recover db connections from poorly written applications which fail to close connections.
setting removeabandonedonmaintenance to true removes abandoned connections on the maintenance cycle (when eviction ends). this property has no effect unless maintenance is enabled by setting timebetweenevicionrunsmillis to a positive value.
标记是否删除泄露的连接,如果他们超过了removeabandonedtimout的限制。
如果设置为true, 连接被认为是被泄露并且可以被删除,如果空闲时间超过removeabandonedtimeout.
设置为true可以为异常没有关闭连接的程序修复数据库连接。
datasource.removeabandonedtimeout=120
timeout in seconds before an abandoned connection can be removed.
泄露的连接可以被删除的超时值, 单位秒
datasource.logabandoned=true
flag to log stack traces for application code which abandoned a statement or connection.
logging of abandoned statements and connections adds overhead for every connection open or new statement because a stack trace has to be generated.
标记当statement或连接被泄露时是否打印程序的stack traces日志。
被泄露的statements和连接的日志添加在每个连接打开或者生成新的statement,因为需要生成stack trace。
if you have enabled removeabandonedonmaintenance or removeabandonedonborrow then it is possible that a connection is reclaimed by the pool because it is considered to be abandoned. this mechanism is triggered when (getnumidle() < 2) and (getnumactive() > getmaxtotal() - 3) and removeabandonedonborrow is true; or after eviction finishes and removeabandonedonmaintenance is true. for example, maxtotal=20 and 18 active connections and 1 idle connection would trigger removeabandonedonborrow, but only the active connections that aren't used for more then "removeabandonedtimeout" seconds are removed (default 300 sec). traversing a resultset doesn't count as being used. creating a statement, preparedstatement or callablestatement or using one of these to execute a query (using one of the execute methods) resets the lastused property of the parent connection.
如果开启"removeabandoned",那么连接在被认为泄露时可能被池回收。这个机制在(getnumidle() < 2) and (getnumactive() > getmaxactive() - 3)时被触发。
举例当maxactive=20, 活动连接为18,空闲连接为1时可以触发"removeabandoned"。
但是活动连接只有在没有被使用的时间超过"removeabandonedtimeout"时才被删除,默认300秒。
在resultset中游历不被计算为被使用。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯