gpt4 book ai didi

java - 在 oracle.jdbc.pool.OracleDataSource 上设置池属性

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:49 25 4
gpt4 key购买 nike

我将 oracle.jdbc.pool.OracleDataSource 用于连接池。我希望池检查连接是否未正确关闭并 catch 它。我尝试了以下方法:

ods = new OracleDataSource();

ods.setConnectionCachingEnabled(true);
ods.setConnectionCacheName(CACHE_NAME);

Properties cacheProps = new Properties();
cacheProps.setProperty("MinLimit", Integer.toString(1));
cacheProps.setProperty("MaxLimit", Integer.toString(6));
cacheProps.setProperty("InitialLimit", "1");
cacheProps.setProperty("AbandonedConnectionTimeout", "2");

ods.setConnectionCacheProperties(cacheProps);

我这样检查 Activity 连接:

occm = OracleConnectionCacheManager.getConnectionCacheManagerInstance();
occm.getNumberOfActiveConnections(CACHE_NAME);

如果我不关闭应用程序中的连接,池将填充到 6,所以

cacheProps.setProperty("AbandonedConnectionTimeout", "2");

不工作。为什么?

任何提示将不胜感激

最佳答案

根据 Oracle's tutorial还涉及另一个属性。

When the cache is created, three important properties, the PropertyCheckInterval, AbandonedConnectionTimeout and LowerThresholdLimit are set. PropertyCheckInterval sets the time interval at which the cache manager inspects and enforces all specified cache properties.

也尝试设置

 cacheProps.setProperty("PropertyCheckInterval", "1");

默认为 15 分钟...

不过,两秒对于被视为已放弃的连接来说可能有点短,而且由于您还必须显式设置检查间隔,我想这会涉及一些开销。由于您真的非常想在应用程序代码中正确关闭连接并且只在极少数情况下依赖它,因此您可能应该为两者设置更高的值。

关于java - 在 oracle.jdbc.pool.OracleDataSource 上设置池属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3931629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com