jboss wildfly数据源连接失败 - 在配置的阻塞超时内没有可用的托管连接

时间:2015-01-29 10:46:53

标签: java mysql database-connection datasource wildfly-8

我有一个jboss wildfly服务器通过app服务器上配置的数据源连接到mysql数据库。

有一段时间,mysql数据库无法访问一段时间(网络问题等等),当mysql无法访问时,我会在日志中收到消息:

09:42:30,015 ERROR [org.jboss.seam.async.AsynchronousExceptionHandler] (4pm_services_QuartzScheduler_Worker-4) Exception thrown whilst executing asynchronous call: java.
lang.RuntimeException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection

这是预期的,因为当时你的mysql不可用,问题是,当mysql服务器再次联机时,错误仍然存​​在,并且jboss服务器无法从连接池中获取有效信息。

我有: 野生动物8.1 mysql 5.5 使用JPA与数据库进行通信

这是数据源配置:

<datasource jta="true" jndi-name="java:jboss/services_DS" pool-name="fourPmDSServices" enabled="true" use-java-context="true">
                    <connection-url>jdbc:mysql://192.168.10.110:3306/FOUR_PM__SERVICES?useUnicode=true&amp;characterEncoding=UTF-8</connection-url>
                    <driver>mysql</driver>
                    <new-connection-sql>select 1</new-connection-sql>
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                    <pool>
                        <min-pool-size>1</min-pool-size>
                        <max-pool-size>5</max-pool-size>
                        <prefill>true</prefill>
                        <use-strict-min>false</use-strict-min>
                    </pool>
                    <security>
                        <user-name>*********</user-name>
                        <password>*********</password>
                    </security>
                    <validation>
                        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
                        <check-valid-connection-sql>select 1</check-valid-connection-sql>
                        <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLStaleConnectionChecker"/>
                        <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
                    </validation>
                    <statement>
                        <prepared-statement-cache-size>10</prepared-statement-cache-size>
                        <share-prepared-statements>true</share-prepared-statements>
                    </statement>
                </datasource>

这是错误的完整堆栈跟踪:

00:00:00,017 WARN  [org.hibernate.util.JDBCExceptionReporter] (4pm_services_QuartzScheduler_Worker-2) SQL Error: 0, SQLState: null
00:00:00,018 ERROR [org.hibernate.util.JDBCExceptionReporter] (4pm_services_QuartzScheduler_Worker-2) javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/services_DS
00:00:00,018 ERROR [org.jboss.seam.async.AsynchronousExceptionHandler] (4pm_services_QuartzScheduler_Worker-2) Exception thrown whilst executing asynchronous call: java.lang.RuntimeException: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at si.arctur.fourPmServices.scheduleJobs.QuartzJobBase.executeInternal(QuartzJobBase.java:91) [4pm_services-ejb.jar:]
    at si.arctur.fourPmServices.scheduleJobs.QuartzJobBase.schedule(QuartzJobBase.java:76) [4pm_services-ejb.jar:]
    at sun.reflect.GeneratedMethodAccessor98.invoke(Unknown Source) [:1.6.0_32]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.6.0_32]
    at java.lang.reflect.Method.invoke(Method.java:622) [rt.jar:1.6.0_32]
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.async.AsynchronousInterceptor.aroundInvoke(AsynchronousInterceptor.java:52) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) [jboss-seam.jar:2.2.2.Final]
    at si.arctur.fourPmServices.scheduleJobs.emailSender.MailChecker_$$_javassist_seam_2.schedule(MailChecker_$$_javassist_seam_2.java) [4pm_services-ejb.jar:]
    at sun.reflect.GeneratedMethodAccessor104.invoke(Unknown Source) [:1.6.0_32]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.6.0_32]
    at java.lang.reflect.Method.invoke(Method.java:622) [rt.jar:1.6.0_32]
    at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.util.Reflections.invokeAndWrap(Reflections.java:144) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.async.AsynchronousInvocation$1.process(AsynchronousInvocation.java:62) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.async.Asynchronous$ContextualAsynchronousRequest.run(Asynchronous.java:80) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.async.AsynchronousInvocation.execute(AsynchronousInvocation.java:44) [jboss-seam.jar:2.2.2.Final]
    at org.jboss.seam.async.QuartzDispatcher$QuartzJob.execute(QuartzDispatcher.java:243) [jboss-seam.jar:2.2.2.Final]
    at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [quartz.jar:1.6.0]
    at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529) [quartz.jar:1.6.0]
Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1389) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:255) [hibernate-core.jar:3.6.10.Final]
    at si.arctur.fourPmServices.scheduleJobs.emailSender.MailChecker.checkQueue(MailChecker.java:37) [4pm_services-ejb.jar:]
    at si.arctur.fourPmServices.scheduleJobs.emailSender.MailChecker.execute(MailChecker.java:26) [4pm_services-ejb.jar:]
    at si.arctur.fourPmServices.scheduleJobs.QuartzJobBase$TransactionalWork.work(QuartzJobBase.java:144) [4pm_services-ejb.jar:]
    at org.jboss.seam.util.Work.workInTransaction(Work.java:61) [jboss-seam.jar:2.2.2.Final]
    at si.arctur.fourPmServices.scheduleJobs.QuartzJobBase.executeInternal(QuartzJobBase.java:89) [4pm_services-ejb.jar:]
    ... 30 more
Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
    at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1700) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.doQuery(Loader.java:801) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.doList(Loader.java:2542) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.Loader.list(Loader.java:2271) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:459) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:365) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:246) [hibernate-core.jar:3.6.10.Final]
    ... 35 more
Caused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/services_DS
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
    at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71) [hibernate-core.jar:3.6.10.Final]
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) [hibernate-core.jar:3.6.10.Final]
    ... 49 more
Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/services_DS
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:390)
    at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:368)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
    at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
    ... 51 more
Caused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms])
    at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:377)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getTransactionNewConnection(AbstractPool.java:495)
    at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:374)
    at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:329)
    ... 54 more

7 个答案:

答案 0 :(得分:7)

看起来您需要为失败的连接定义刷新策略。 检查&#34; flush-strategy&#34; PARAM。

开始的一个好点是: https://docs.jboss.org/author/display/WFLY8/DataSource+configuration

他们参考了这个XSD: http://www.ironjacamar.org/doc/schema/datasources_1_1.xsd

XSD解密就在这里: http://www.ironjacamar.org/doc/userguide/1.2/en-US/html_single/index.html#deployingds

在您的情况下,我会尝试找出网络问题。 独立于此。我会在你的情况下(连接错误)刷新我的完整连接池: flush-strategy =&gt; EntirePool

祝福解决这样一个奇怪的问题

答案 1 :(得分:4)

消息没有可用的托管连接是什么意思?

这意味着正在使用与db的所有可能连接和/或线程已超时,等待连​​接打开。

可能的解决方案:

增加连接池大小

添加

<强> <max-pool-size>whatever</max-pool-size>

到你的-ds.xml文件中增加

可用的连接数。默认值为20

有一个属性

<强> MaxConnectionsInUse

可以在jmx-console上查看

ManagedConnectionPool

可以帮助您了解您真正需要的连接数。

告诉您的主题等待更长时间才能打开连接

添加

<强> <blocking-timeout-millis>whatever</blocking-timeout-millis>

到你的-ds.xml文件以增加等待的时间长度。默认值为30000(JBoss-3.2.4之前为5000)毫秒。

确保正确关闭打开的连接

答案 2 :(得分:1)

我也遇到了这个问题。但是,我的连接短暂运行,然后在许多请求后停止工作。原来是与数据库的未关闭连接,这导致连接被消耗并最终耗尽了连接池。简单地增加连接池的大小只会延迟最终的错误。您需要确定无法正确关闭连接的位置才能解决此问题。

答案 3 :(得分:0)

在standalone-ha.xml

中的JCA中

debug =“true”error =“true”

验证jca子系统中是否存在并设置debug =“true”。           ...                      ...         然后在server.log中,如果任何连接没有关闭代码的堆栈跟踪,它将写入。

答案 4 :(得分:0)

我有一个类似的问题,我修复了@Harsh说的答案。我将maxpoolsize从20增加到100,问题就消失了。

答案 5 :(得分:-2)

引起:javax.resource.ResourceException:IJ000655:配置的阻塞超时(30000 [ms]内)没有可用的托管连接

此消息说,配置的池无法在配置的3秒(3000毫秒)超时内提供任何连接。您的池太低或者您的连接在使用后没有关闭,可能会增加池大小。

还要检查JBoss附近的连接。

答案 6 :(得分:-2)

引起:javax.resource.ResourceException:IJ000453:无法获得java的托管连接:jboss / services_DS

似乎问题与某些数据库表和java配置(如hbm.xml)有关。对于每个Table Type参数,java api打开与数据库的连接或由于某些其他环境配置。

请参阅以下链接,您将遇到与解决方案相同的问题。

https://developer.jboss.org/thread/211940

http://www.coderanch.com/t/556721/JBoss/Jboss-Datasource-configured-correctly-unable