You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多模块Maven项目(Spring+Hibernate+Tomcat)内存泄漏排查求助

多模块Maven项目(Spring+Hibernate+Tomcat)内存泄漏排查求助

环境概述

  • Java版本:17
  • Tomcat版本:10
  • JNDI数据源:由Tomcat管理
  • MySQL驱动:mysql-connector-j-9.1.0(仅存于Tomcat的lib目录,未在Maven POM中引入)
  • Spring框架版本:6.2.0
  • Spring Security版本:6.2.3
  • Hibernate版本:6.2.0.Final
  • Hibernate Commons版本:7.0.1.Final

相关配置

HikariCP数据源配置

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
    <property name="dataSourceJNDI" value="java:/comp/env/jdbc/xxx" />  
    <property name="maximumPoolSize" value="10" />
    <property name="minimumIdle" value="10" />   
    <property name="idleTimeout" value="300000" />   
    <property name="connectionTestQuery" value="SELECT 1" />
    <property name="leakDetectionThreshold" value="30000" />
    <property name="autoCommit" value="true" />
</bean>

EntityManager配置

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="xxxxx" />
    <property name="dataSource" ref="dataSource" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="generateDdl" value="false" />
        </bean>
    </property>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
            <entry key="hibernate.enable_lazy_load_no_trans" value="true" />
            <entry key="hibernate.jdbc.batch_size" value="50" />
        </map>
    </property>
</bean>

Tomcat中的JNDI资源配置

<Resource name="jdbc/MainDB" auth="Container"
          type="javax.sql.DataSource" username="rrrrr" password="ttttt"
          driverClassName="com.mysql.cj.jdbc.Driver"
          url="jdbc:mysql://xxxxx/yyyyy?useSSL=false&amp;dontTrackOpenResources=true"
          maxIdle="4" maxTotal="2000" minIdle="2"
          testOnBorrow="true" validationQuery="SELECT 1" 
          removeAbandonedOnBorrow="true" removeAbandonedTimeout="600"
          logAbandoned="true" />

抽象DAO实现(GenericDaoImpl)

@PersistenceContext
protected EntityManager entityManager;

问题现状

项目中出现多处内存泄漏,已通过SonarQube、PMD、CheckStyle、SpotBugs等工具排查,未找到根因。

未直接管理会话或连接,所有操作均委托给Tomcat、Hibernate和Spring。尽管配置了HikariCP并使用JNDI管理连接池,内存泄漏问题仍存在。

怀疑方向

  • Tomcat对MySQL驱动的处理方式
  • Hibernate的懒加载或批处理配置

已启用Hibernate的generate_statistics和show_sql选项,未发现异常。

求助需求

恳请协助排查该问题,或提供类似架构下内存泄漏常见诱因的指导,也欢迎推荐可能忽略的工具、方法或配置。

内容的提问来源于stack exchange,提问作者user13596971

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 20:42:13