当前位置: 首页 > 知识库问答 >
问题:

如何配置Quarkus以超越20个Mysql连接?

邵博艺
2023-03-14

我无法超越20 MySQL连接,而与Quarkus工作。

以下是应用程序的内容。使用的属性文件:

quarkus.datasource.url=jdbc:mysql://localhost:3306/testdb?zeroDateTimeBehavior=convertToNull
quarkus.datasource.driver=com.mysql.cj.jdbc.Driver
quarkus.datasource.username =root
quarkus.datasource.password =
quarkus.http.test-port=38030
quarkus.http.port=38030
quarkus.datasource.jdbc.initial-size=50
quarkus.datasource.jdbc.max-size=100

我正在使用下面persistence.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
             http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="GenerateWorkerPU" transaction-type="RESOURCE_LOCAL">

        <description>Hibernate test case template Persistence Unit</description>

        <properties>
            <!-- intentionally using worse case so that we can optimise for this -->
            <property name="hibernate.archive.autodetection" value="class, hbm"/>

            <!-- Connection specific -->
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/>
            <property name="hibernate.connection.pool_size" value="1000"/>

            <!-- Tuning and debugging -->
            <property name="hibernate.show_sql" value="false"/>
            <property name="hibernate.format_sql" value="false"/>

            <!--
                Optimistically create the tables;
                will cause background errors being logged if they already exist,
                but is practical to retain existing data across runs (or create as needed) 
                <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
                -->
            <!-- drop-and-create create-only -->


            <property name="javax.persistence.validation.mode" value="NONE"/>
        </properties>

    </persistence-unit>
</persistence>

以及以下注释:

@PersistenceUnit (unitName = "GenerateWorkerPU")
EntityManagerFactory emf;

这些使我不用深入修改来自wildfly 13的代码。

代码运行良好,但超过20个Mysql连接后,我从日志中得到以下错误:

2020-05-17 19:11:14,791 WARN  [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-2) SQL Error: 0, SQLState: null
2020-05-17 19:11:14,791 ERROR [org.hib.eng.jdb.spi.SqlExceptionHelper] (executor-thread-2) Sorry, acquisition timeout!
2020-05-17 19:11:14,798 SEVERE [DAO.GenerateCertStatusDaoV2] (executor-thread-2) null: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1542)
        at org.hibernate.query.internal.AbstractProducedQuery.getSingleResult(AbstractProducedQuery.java:1581)
        at DAO2.GenerateCertStatusDaoV2.findByName(GenerateCertStatusDaoV2.java:53)
        at threading2.SignatureProducerCV1.call(SignatureProducerCV1.java:87)
        at threading2.SignatureProducerCV1.call(SignatureProducerCV1.java:33)
        at io.smallrye.context.SmallRyeThreadContext$ContextualCallable.call(SmallRyeThreadContext.java:117)
        at io.quarkus.runtime.CleanableExecutor$CleaningCallable.call(CleanableExecutor.java:246)
        at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
        at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
        at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1426)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at java.base/java.lang.Thread.run(Thread.java:834)
        at org.jboss.threads.JBossThread.run(JBossThread.java:479)
Caused by: org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99)
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:107)
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:134)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.connection(StatementPreparerImpl.java:50)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:149)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:176)
        at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:151)
        at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2104)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2034)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2012)
        at org.hibernate.loader.Loader.doQuery(Loader.java:953)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
        at org.hibernate.loader.Loader.doList(Loader.java:2838)
        at org.hibernate.loader.Loader.doList(Loader.java:2820)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2652)
        at org.hibernate.loader.Loader.list(Loader.java:2647)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1404)
        at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1565)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1533)
        ... 15 more
Caused by: java.sql.SQLException: Sorry, acquisition timeout!
        at io.agroal.pool.ConnectionPool.handlerFromSharedCache(ConnectionPool.java:244)
        at io.agroal.pool.ConnectionPool.getConnection(ConnectionPool.java:173)
        at io.agroal.pool.DataSource.getConnection(DataSource.java:66)
        at io.quarkus.hibernate.orm.runtime.customized.QuarkusConnectionProvider.getConnection(QuarkusConnectionProvider.java:23)
        at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:38)
        at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:104)
        ... 35 more

共有1个答案

萧和平
2023-03-14

quarkus。数据源。jdbc。最大尺寸quarkus。数据源。jdbc。初始大小属性必须命名为quarkus。数据源。最大尺寸quarkus。数据源。初始大小,因为在其他情况下,它们应用于名为jdbc的命名数据源,而不是全局未命名的默认数据源,我想您应该使用该数据源。其他数据源属性适用于未命名的数据源。默认的max size是20,这就是为什么不能获得超过20个连接。

 类似资料:
  • 我有一个使用Jetty启动的spring应用程序。 bean配置: 我在启动应用程序时遇到以下错误: 依赖关系信息: 我是Spring的新人。感谢您的支持!

  • 要连接到以太坊测试网,是这样的: (摘自此处:https://hardhat.org/tutorial/deploying-to-a-live-network.html ) 如何为RSK Testnet添加网络配置? (请注意,我使用的是种子短语,而不是原始私钥)

  • 我想更改quarkus应用程序的日志级别,在我可以找到任何引用的地方,它都指向application.properties文件。 我需要任何额外的扩展来让它工作吗? 我读过这个问题,但对我不起作用。我真的不知道,我从Quarkus bootstrap创建了一个简单的应用程序,但我仍然有同样的行为。

  • 本文向大家介绍Ubuntu 18.04配置mysql以及配置远程连接的步骤,包括了Ubuntu 18.04配置mysql以及配置远程连接的步骤的使用技巧和注意事项,需要的朋友参考一下 前言 本文主要跟大家分享了关于Ubuntu 18.04配置mysql及配置远程连接的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 配置教程如下: 首先是大家都知道的老三套,啥也不说上来就放

  • 我的WebApp使用多个数据库,我尝试使用GlassFish连接池来管理连接,但我发现配置示例只使用一个数据库。 那么,我该怎么办?创建与我正在使用的数据库数量相同的连接池,或者是否有方法将一个池配置为多个数据库?

  • 我正在使用带有连接池的reactor-netty http客户端(0.7.X系列),我想配置池连接的空闲超时,但不知道在哪里。 更准确地说,我需要配置reactor-netty http客户端连接池,使其能够自动关闭在可配置超时内未看到任何活动的连接。这些连接是开放的,但在一段(可配置的)时间内没有传输字节。 如何配置reactory-netty超文本传输协议客户端抢先关闭空闲连接?