我在 karaf 中的 pax-jdbc 的池连接有问题,我正在尝试通过 blueprint.xml 将 Mysql 数据源(DS)注入到我的项目中,为了测试它,我构建了一个 karaf 命令,将 DS 注入karaf 命令类并使用该连接执行查询。没关系,但问题是当我多次执行命令时,每次执行都会创建一个新的 DS 实例,并且池连接无法打开与 MySQL 的新连接,因为池已达到限制。
我已在此链接中将我的代码上传到 github:https ://github.com/christmo/karaf-pax-jdbc ,如果您在此项目中发现错误,可以提出拉取请求。
为了测试这个项目,你可以这样做:
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
如果你执行这个命令“mysql-connection”9次,它会冻结karaf的提示,如果你中断执行,你会得到这个异常:
java.sql.SQLException:无法获得连接,在 org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:146) 在 com.twim.OrmCommand.execute(OrmCommand.java:53) 在 org. apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83) 在 org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67) 在org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87) 在 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。 org.apache.felix.gogo.runtime.Closure 的 Closure.execute(Closure.java:182)。在 org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java: 270) 在 java.lang.Thread.run(Thread.java:745) 引起:java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueuedSynchronizer.java:2014) 在 java.util. .concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2048) 在 org.apache.commons.pool2.impl.LinkedBlockingDeque.takeFirst(LinkedBlockingDeque.java:583) 在 org.apache.commons.pool2.impl.GenericObjectPool .borrowObject(GenericObjectPool.java:442) 在 org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) 在 org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:134) ... 还有 12 个