简体   繁体   English

Oracle 数据库连接未从 Tomcat 中的连接池释放 8

[英]Oracle DB connections not releasing from connection pool in Tomcat 8

We are migrating Tomcat6, java 6 and Oracle 10g web-applications to Tomcat 8, Java 8 and Oracle 10g.我们正在将 Tomcat6、java 6 和 Oracle 10g Web 应用程序迁移到 Tomcat 8、Java 8 和 Oracle 10g。 Our applications working fine after migrated, but initial connections (initialSize="5") available in connection pool not released after Tomcat shut down.我们的应用程序在迁移后工作正常,但在 Tomcat 关闭后连接池中可用的初始连接(initialSize="5")未释放。 When second time starting tomcat, its creating 5 more initial connections to pool.第二次启动 tomcat 时,它会再创建 5 个到池的初始连接。 I am using below resource configuration in server.xml我在 server.xml 中使用以下资源配置

<Resource   name="TestAppDataSource"
            auth="Container"
            factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
            type="javax.sql.DataSource"
            driverClassName="oracle.jdbc.OracleDriver"
            initialSize="5"
            maxActive="40"
            maxIdle="40"
            minIdle="5"
            timeBetweenEvictionRunsMillis="30000"
            minEvictableIdleTimeMillis="30000"
            maxWait="10000"
            testWhileIdle="true"
            testOnBorrow="true"
            testOnReturn="false"
            validationQuery="SELECT 1 from dual"
            validationInterval="30000" 
            logAbandoned="true"
            removeAbandonedTimeout="30"
            removeAbandonedOnBorrow="true"
            removeAbandonedOnMaintenance="true"
            suspectTimeout="300"
            maxAge="60000"
            url="jdbc:oracle:thin:@//IP_ADDRESS:1521/SCHEMA_NAME"
            username="USER_NAME"
            password="PASSWORD" />

And below resource link configuration in application META_INF/context.xml以及应用程序 META_INF/context.xml 中的资源链接配置

<ResourceLink
    name="APP_TEST"
    global="TestAppDataSource" 
    type="javax.sql.DataSource"
/>

I am using ojdbc7.jar for oracle driver.我正在为 oracle 驱动程序使用 ojdbc7.jar。 Please help whether i missed any configuration..请帮助我是否错过任何配置..

try with the follow option: 尝试以下选项:

removeAbandoned = true 

(boolean) Flag to remove abandoned connections if they exceed the removeAbandonedTimeout. (布尔值)标记以在放弃的连接超过removeAbandonedTimeout时删除它们。 If set to true a connection is considered abandoned and eligible for removal if it has been in use longer than the removeAbandonedTimeout Setting this to true can recover db connections from applications that fail to close a connection. 如果设置为true,则连接的使用时间长于removeAbandonedTimeout,如果该连接的使用时间超过removeAbandonedTimeout,则将其视为已被删除,并且可以删除该连接。如果将此设置为true,则可以从无法关闭连接的应用程序中恢复数据库连接。 See also logAbandoned The default value is false. 另请参见logAbandoned默认值为false。

Tomcat now use JDBC Connection Pool org.apache.tomcat.jdbc.pool that is a replacement or an alternative to the Apache Commons DBCP connection pool. Tomcat现在使用JDBC连接池org.apache.tomcat.jdbc.pool代替Apache Commons DBCP连接池。

removeAbandoned is a option for JDBC Connection Pool removeAbandoned是JDBC连接池的选项

https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html

You have to add closeMethod="close" to your JDBC resource in context.xml. 您必须在context.xml中向您的JDBC资源添加closeMethod="close" That way, Tomcat properly releases pending connections to the database. 这样,Tomcat可以正确释放与数据库的挂起连接。

Nitpick: when tomcat is shut down, the JVM is shut down, hence all of its resources are "released" too, and there is no more connection pool - what you meant is that the connections are not properly being shut down, so the DB is not being notified that they're closed, and hence the sessions there are not being ended. Nitpick:当 tomcat 关闭时,JVM 也被关闭,因此它的所有资源也被“释放”,并且没有更多的连接池 - 你的意思是连接没有正确关闭,所以数据库没有被通知他们已经关闭,因此那里的会议没有结束。 This is either because the pool is not getting a shutdown command, or because something else is hanging in tomcat during shutdown and hence it's not getting to the point of shutting down the pool, being force-killed by the shutdown script after a wait timeout has expired.这要么是因为池没有收到关闭命令,要么是因为在关闭期间其他东西挂在 tomcat 中,因此它没有达到关闭池的程度,在等待超时后被关闭脚本强行杀死已到期。 You can take thread dumps during shutdown to see what it's waiting on, and look at catalina.out for messages about leaked threads (...has started a thread... that's not been shut down...).您可以在关闭期间获取线程转储以查看它正在等待什么,并查看 catalina.out 以获取有关泄漏线程的消息(...已启动一个线程...尚未关闭...)。 It is a common problem that webapps will launch long-running threads without daemonizing them - such webapps need to implement a ServletContextListener that will stop this thread/resource when the ServletContext is stopped.这是一个常见的问题,即 webapps 将在没有守护进程的情况下启动长时间运行的线程——这样的 webapps 需要实现一个 ServletContextListener,它会在 ServletContext 停止时停止该线程/资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM