错误org.hibernate.engine.jdbc.spi.SqlExceptionHelper-HikariPool-1-连接不可用,请求超时

时间:2019-04-30 15:10:41

标签: java oracle spring-boot spring-data-jpa hikaricp

我们已经在tomcat服务器上制作了一个rest spring boot spring数据应用程序。该应用程序可以在本地环境中工作。但是,当部署到生产环境中时,该应用程序在并发命中之后会给出以下异常。

例外: 错误org.hibernate.engine.jdbc.spi.SqlExceptionHelper-HikariPool-1-连接不可用,请求在30004ms后超时。 javax.persistence.PersistenceException:

org.hibernate.exception.JDBCConnectionException:无法获取JDBC连接

原因:org.hibernate.exception.JDBCConnectionException:无法获取JDBC连接

该应用程序被部署为apache tomcat中的war文件,将单个数据源连接到oracle

配置如下:- application.properties如下:-

    spring.datasource.url=jdbc:oracle:thin:@xx.xx.xx.xx:1521/orcl
    spring.datasource.username=XXXX
    spring.datasource.password=XXXX
    spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
    spring.jpa.show-sql=true
    spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
    spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
    spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
    spring.jpa.properties.hibernate.globally_quoted_identifiers=true
    spring.datasource.hikari.connection-test-query=SELECT 1 FROM DUAL


    spring.datasource.hikari.connection-timeout=60000
    spring.datasource.hikari.maximum-pool-size=10
    spring.datasource.hikari.idleTimeout=60000
    spring.datasource.hikari.minimumIdle=5
    spring.datasource.hikari.idleTimeout=30000
    spring.datasource.hikari.poolName=SpringBootJPAHikariCP
    spring.datasource.hikari.maxLifetime=2000000
    spring.datasource.hikari.connectionTimeout=60000
logging.level.com.zaxxer = DEBUG
logging.level.com.zaxxer.hikari.HikariConfig=DEBUG


logging.level.org.hibernate=DEBUG
logging.level.org.hibernate.tool.hbm2ddl=trace
logging.level.org.hibernate.tool.hbm2ddl.SchemaUpdate = trace
logging.level.org.hibernate.type.descriptor.sql=trace
logging.level.org.hibernate.SQL=INFO
logging.level.org.hibernate.type=TRACE

此外,oracle数据库SP文件如下

DB11G.__java_pool_size=16777216
DB11G.__large_pool_size=33554432
DB11G.__oracle_base='/data/app/oracle'#ORACLE_BASE set from environment
DB11G.__pga_aggregate_target=2382364672
DB11G.__sga_target=4294967296
DB11G.__shared_io_pool_size=0
DB11G.__shared_pool_size=2130706432
DB11G.__streams_pool_size=16777216
*.audit_file_dest='/data/app/oracle/admin/orcl/adump'
*.audit_trail='db'
*.compatible='11.2.0.4.0'
*.control_files='/data/app/oracle/oradata/orcl/cC  C"           F.  ontrol01.ctl','/data/app/oracle/fast_recovery_area/orcl/control02.ctl'
*.db_block_size=8192
*.db_domain=''
*.db_name='orcl'
*.db_recovery_file_dest='/data/app/oracle/fast_recovery_area'
*.db_recovery_file_dest_size=4385144832
*.diagnostic_dest='/data/app/oracle'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=DB11GXDB)'
*.open_cursors=300
*.pga_aggregate_target=2367684608
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=4293918720
*.undo_tablespace='UNDOTBS1'

数据库部署在16 GB Ram上 春季启动pom.xml如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>   
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.mpcz.services.api</groupId>
    <artifactId>CommonServicePortal</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>CommonServicePortal</name>
    <description>Services</description>
    <properties>
        <java.version>1.8</java.version>

    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>
<!-- https://mvnrepository.com/artifact/xerces/xercesImpl -->
<dependency>
    <groupId>com.xercesImpl</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.12.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xml-apis/xml-apis -->
<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- For Working with Json Web Tokens (JWT) -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- marked the embedded servlet container as provided -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.6.0</version>
        </dependency>
        <!-- hot swapping, disable cache for template, enable live reload -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>1.3.3.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.4.0</version>
        </dependency>
        <!-- Optional, for bootstrap -->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>3.3.7</version>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc14</artifactId>
            <scope>compile</scope>
            <version>1.0</version>
        </dependency>

        <dependency>
            <groupId>com.mpmvvcl.mpmk</groupId>
            <artifactId>Common-Domain</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>com.paytm</groupId>
            <artifactId>paytmchecksum</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.tcs</groupId>
            <artifactId>pgi</artifactId>
            <scope>compile</scope>
            <version>1.0</version>
        </dependency>       
        <dependency>
            <groupId>com.mpmvvcl.mpmk</groupId>
            <artifactId>MPMK-Utilities</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-activemq</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-spring</artifactId>
            <version>5.13.3</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.modelmapper</groupId>
            <artifactId>modelmapper</artifactId>
            <version>2.3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.2.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.7</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20180813</version>
        </dependency>

    </dependencies>

    <build>
        <finalName>serviceportal</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

hikari的记录如下:

2019-04-30 14:50:39:633 DEBUG HikariPool - HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=2)
2019-04-30 14:50:39:508 DEBUG HikariPool - HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=3)
2019-04-30 14:55:08:420 DEBUG SqlExceptionHelper - Unable to acquire JDBC Connection [n/a]
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 298435ms.
    at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:591)
    at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:194)

Oracle数据库统计信息

RESOURCE_NAME                  CURRENT_UTILIZATION MAX_UTILIZATION LIMIT_VALUE
------------------------------ ------------------- --------------- ----------
processes                                       53             150        150
sessions                                        58             156        248

请检查配置并提供解决方案, HikariCP之前可能与服务器关闭连接有关,但是我不确定。任何对此的评论将不胜感激。

0 个答案:

没有答案