Задать вопрос
@Nikitoz138

Как правильно закрывать пул подключений UCP в Tomcat 9 (oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser)?

В CATALINA_HOME/lib лежат библиотеки ucp и ojdbc7 для работы с БД.
Каждая WARка(проект), которая лежит в webapps, работает с этими библиотеками.
К проектам я их подключаю через Gradle:
dependencies {
providedCompile ':ojdbc7'
providedCompile ':ucp'
.....................
}
Через StoredProcedure(JDBCTemplate) обращаюсь к хранимым процедурам в БД в проектах.
dataSource создаю через бин:
<bean id="dataSource" class=".............PoolDataSourceSpringImpl" destroy-method="destroy">
        <property name="connectionFactoryClassName" value="${ORACLE_CONNECTION_FACTORY_CLASS_NAME}"/>
        <property name="URL" value="${ORACLE_URL}"/>
        <property name="user" value="${ORACLE_USER}"/>
        <property name="password" value="${ORACLE_PASSWORD}"/>
        <property name="connectionPoolName" value="${ORACLE_POOL_NAME}"/>
        <property name="initialPoolSize" value="${ORACLE_INITIAL_POOL_SIZE}"/>
        <property name="minPoolSize" value="${ORACLE_MIN_POOL_SIZE}"/>
        <property name="maxPoolSize" value="${ORACLE_MAX_POOL_SIZE}"/>
        <property name="connectionWaitTimeout" value="${ORACLE_CONNECTION_WAIT_TIMEOUT}"/>
        <property name="abandonedConnectionTimeout" value="${ORACLE_ABANDONED_CONNECTION_TIMEOUT}"/>
        <property name="timeToLiveConnectionTimeout" value="${ORACLE_TIME_TO_LIVE_CONNECTION_TIMEOUT}"/>
        <property name="inactiveConnectionTimeout" value="${ORACLE_INACTIVE_CONNECTION_TIMEOUT}"/>
        <property name="validateConnectionOnBorrow" value="${ORACLE_VALIDATE_CONNECTION_ON_BORROW}"/>
    </bean>

Запускается Tomcat9 и работает нормально:
28-Jun-2018 16:23:36.867 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.5
28-Jun-2018 16:23:36.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Feb 6 2018 21:42:23 UTC
28-Jun-2018 16:23:36.869 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.5.0
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Windows 7
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            6.1
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          x86
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             C:\Program Files (x86)\Java\jdk1.8.0_121\jre
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_121-b13
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         D:\tomcatDeployService
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         D:\tomcatDeployService
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=D:\tomcatDeployService
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=D:\tomcatDeployService
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=D:\tomcatDeployService\endorsed
28-Jun-2018 16:23:36.870 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=D:\tomcatDeployService\temp
28-Jun-2018 16:23:36.871 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
28-Jun-2018 16:23:36.871 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=D:\tomcatDeployService\conf\logging.properties
28-Jun-2018 16:23:36.872 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: exit
28-Jun-2018 16:23:36.872 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: abort
28-Jun-2018 16:23:36.872 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms128m
28-Jun-2018 16:23:36.873 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx256m
28-Jun-2018 16:23:37.007 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["https-jsse-nio-172.20.50.38-8443"]
28-Jun-2018 16:23:37.250 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
28-Jun-2018 16:23:37.256 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 656 ms
28-Jun-2018 16:23:37.268 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
28-Jun-2018 16:23:37.268 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.5
28-Jun-2018 16:23:37.317 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [D:\tomcatDeployService\webapps\test.war]
28-Jun-2018 16:23:41.015 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [D:\tomcatDeployService\webapps\test.war] has finished in [3,698] ms
28-Jun-2018 16:23:41.016 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\tomcatDeployService\webapps\ROOT]
28-Jun-2018 16:23:43.382 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\tomcatDeployService\webapps\ROOT] has finished in [2,366] ms
28-Jun-2018 16:23:43.384 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["https-jsse-nio-172.20.50.38-8443"]
28-Jun-2018 16:23:43.395 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 6139 ms

Когда останавливаю сервер возникает ошибка и утечка памяти:
28-Jun-2018 16:23:46.929 INFO [Thread-10] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["https-jsse-nio-172.20.50.38-8443"]
28-Jun-2018 16:23:46.981 INFO [Thread-10] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
28-Jun-2018 16:23:47.031 WARNING [Thread-10] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [test] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:327)
28-Jun-2018 16:23:47.033 INFO [Thread-10] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["https-jsse-nio-172.20.50.38-8443"]

Закрываю пул подключений следующим образом:
public class PoolDataSourceSpringImpl extends PoolDataSourceImpl
{
    public void destroy() throws UniversalConnectionPoolException, InterruptedException {
        String poolName=getConnectionPoolName();
        UniversalConnectionPoolManager mgr= UniversalConnectionPoolManagerImpl.getUniversalConnectionPoolManager();
        mgr.stopConnectionPool(poolName);
        mgr.destroyConnectionPool(poolName);
    }
}

Обновиться до ojdbc8 и использовать JNDI для БД пробовал - возникает та же ошибка.
  • Вопрос задан
  • 366 просмотров
Подписаться 1 Сложный Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы