我已经创建了一个线程应用程序,它正在检查数据库上的某些内容并进行一些事务,但我遇到的问题是无限的非活动连接然后导致数据库挂起
我使用过此代码
KnpLabs/DoctrineBehaviors
任何人有想法吗?
请注意:我已将translatable
值更改为GenericObjectPool connectionPool = new GenericObjectPool(null);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUrl, dbUsername, dbPassword);
connectionPool.setMaxActive(10);
connectionPool.setWhenExhaustedAction((byte) 1);
connectionPool.setMaxWait(30000);
connectionPool.setMaxIdle(-1);
connectionPool.setTestOnBorrow(false);
connectionPool.setTestOnReturn(false);
connectionPool.setTimeBetweenEvictionRunsMillis(-1);
connectionPool.setNumTestsPerEvictionRun(-1);
connectionPool.setMinEvictableIdleTimeMillis(-1);
connectionPool.setTestWhileIdle(false);
PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,connectionPool,null,null,false,true);
poolableConnectionFactory.setValidationQuery(null);
poolableConnectionFactory.setDefaultReadOnly(false);
poolableConnectionFactory.setDefaultAutoCommit(true);
PoolingDriver driver = new PoolingDriver();
driver.registerPool("pro",connectionPool);
conn = DriverManager.getConnection("jdbc:apache:commons:dbcp:pro");
,然后我开始获得异常连接已关闭