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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3931629/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:42:10  来源:igfitidea点击:

Setting Pooling Property on oracle.jdbc.pool.OracleDataSource

javaoracleconnection-pooling

提问by Marcel Menz

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:

我使用 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);

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

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

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

is not working. Why?

不管用。为什么?

Any hint would be appreciated

任何提示将不胜感激

回答by Thilo

According to Oracle's tutorialthere is another property involved.

根据Oracle 的教程,还涉及另一个属性。

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.

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

Try to also set

尝试也设置

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

The default is 15 minutes...

默认为 15 分钟...

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.

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

回答by bedjaoui djounaydi

you must add this property :

您必须添加此属性:

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

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

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