在 oracle.jdbc.pool.OracleDataSource 上设置池属性
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 Oracle 的教程是涉及的另一个财产。
尝试还设置
默认值为 15 分钟...
不过,对于被视为放弃的连接来说,两秒可能有点短,并且由于您还必须显式设置检查间隔,我想这涉及一些开销。由于您确实非常希望在应用程序代码中正确关闭连接,并且仅在极少数情况下依赖此连接,因此您可能应该为两者设置更高的值。
According to Oracle's tutorial there is another property involved.
Try to also set
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.
您必须添加此属性:
you must add this property :