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

发布于 2024-09-27 06:38:11 字数 850 浏览 3 评论 0原文

我使用 oracle.jdbc.pool.OracleDataSource 进行连接池。我希望池检查连接是否未正确关闭并赶上它。我尝试了以下操作:

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);

我像这样检查活动连接:

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

如果我不关闭应用程序中的连接,则池只会填满 6 个,因此

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

无法正常工作。为什么?

任何提示将不胜感激

I use the oracle.jdbc.pool.OracleDataSource for connection pooling. I would like the pool to check whether the connection was not closed properly and to catch it up. I tried the following:

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);

I ckeck the active connections like this:

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

If I dont close the connection in the application the pool is just filling up to 6, so

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

is not working. Why?

Any hint would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

池予 2024-10-04 06:38:11

根据 Oracle 的教程是涉及的另一个财产。

创建缓存时,会设置三个重要属性:PropertyCheckInterval、AbandonedConnectionTimeout 和 LowerThresholdLimit。 PropertyCheckInterval 设置缓存管理器检查和强制执行所有指定缓存属性的时间间隔。

尝试还设置

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

默认值为 15 分钟...

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

According to Oracle's tutorial there is another property involved.

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.

Try to also set

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

The default is 15 minutes...

Two seconds is probably a bit short for a connection to be considered abandoned, though, and since you have to explicitly set the check interval as well, I'd imagine that this involves some overhead. Since you really, really want to close connections properly in application code and only rely on this for very rare cases, you should probably set higher values for both.

╰つ倒转 2024-10-04 06:38:11

您必须添加此属性:

cacheProps.setProperty("InactivityTimeout", "2")

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

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

you must add this property :

cacheProps.setProperty("InactivityTimeout", "2")

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

cacheProps.setProperty("PropertyCheckInterval", "1")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文