开发者

Setting Pooling Property on oracle.jdbc.pool.OracleDataSource

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.setConnectionCache开发者_JAVA百科Name(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


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.


you must add this property :

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

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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜