首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >karaf + pax-jdbc连接池已达到极限

karaf + pax-jdbc连接池已达到极限
EN

Stack Overflow用户
提问于 2016-03-27 17:04:00
回答 1查看 1.3K关注 0票数 0

我在karaf中的pax池连接有问题,我试图通过blueprint.xml将Mysql DataSource ( DS )注入到我的项目中,为了测试它,我构建了一个karaf命令,其中将DS注入karaf命令类并执行带有该连接的查询。这是可以的,但问题是当我多次执行命令时,每次执行都会创建DS的一个新实例,池连接无法打开到MySQL的新连接,因为池已经达到极限。

我已经将我的代码上传到了这个链接中的github:https://github.com/christmo/karaf-pax-jdbc中,如果您在这个项目中发现了一个错误,您可以发出一个拉请求。

要测试此项目,您可以:

代码语言:javascript
复制
1. Download karaf 4.0.4 or apache-karaf-4.1.0-SNAPSHOT
2. Copy the file karaf-pax-jdbc/etc/org.ops4j.datasource-my-ds.cfg to ${karaf}/etc, this file have the mysql 
   configuration change with your mysql configuration data.
4. Start mysql database engine
3. Start karaf -> cd ${karaf}/bin/; ./karaf
4. Add the repo of this project with this karaf command: feature:repo-add mvn:pax/features/1.0-SNAPSHOT/xml/features
5. Install the feature created for this project: feature:install mysql-test
6. Execute the command for test this problem: mysql-connection, this command only execute "Select 1" in mysql

如果执行9次此命令"mysql-connection",它将冻结karaf的提示符,如果中断执行,则可以得到以下异常:

java.sql.SQLException:无法连接,org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146) at com.twim.OrmCommand.execute(OrmCommand.java:53) at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83) at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67) at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.上的一般错误在org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480),org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406),org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108),org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182),org.apache.felix.gogo.runtime.Closure.execute(Closure执行(SecuredCommand.java:87)( org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94) at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270) at java.lang.Thread.run(Thread.java:745)由: java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java的java.lang.InterruptedException造成:2048)在org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:583) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:442) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) . 12

EN

回答 1

Stack Overflow用户

发布于 2016-03-27 21:23:23

代码中的问题在行System.out.println("--DS--: " + ds.getConnection());中。

在那里,您创建了一个连接,但从未关闭它。所以每次打电话你都会把池子里的水抽干。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36250133

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档