开发者

Closing Inactive Sessions using BasicDataSource

In our development database, Oracle 11g R2, we've noticed that connections opened via our Java application, using BasicDataSource, remain open indefinitely. Ideally, we'd like each application instance to have up to 5 concurrent database sessions, however, if a session is inactive for more than 60 seconds, the session should close to reduce memory impact on the database.

Using the following code to set up our BasicDataSource, I can observe that we stay under the 5 database session ceiling, but we never seem to clear inactive sessions:

BasicDataSource ds = new BasicDataSource();
ds.setUrl(getUrlAsString());
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");        
ds.setUsername(getClientOracleUserAsString());              
ds.setPassword(getClientOraclePasswordAsStrin开发者_JS百科g());
ds.setMinIdle(0);
ds.setMaxIdle(5);
ds.setMinEvictableIdleTimeMillis(60000);


Try setting the following:

//Sets the number of connections tested during the eviction process*
numTestsPerEvictionRun=5

//Sets whether idle object evictor will validate connections*
setTestWhileIdle=true

//Sets the validation query to run to validate a connection*
setValidationQuery=SELECT 1

It could also be that you are not closing connections properly in the application layer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜