【问题标题】:Hibernate memory leak -BoundedConcurrentHashMapHibernate 内存泄漏 -BoundedConcurrentHashMap
【发布时间】:2017-08-31 11:34:24
【问题描述】:

请帮助解决 Spring MVC 应用程序中的内存问题

请找到我的交易配置

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
        destroy-method="close" p:driverClass="${jdbc.driverClassName}"
        p:jdbcUrl="${jdbc.databaseurl}${jdbc.encoding}" p:user="${jdbc.username}" p:password="${jdbc.password}"
        p:minPoolSize="${minPoolSize}" p:maxPoolSize="${maxPoolSize}"
        p:checkoutTimeout="${checkoutTimeout}" p:maxIdleTime="${maxIdleTime}"
        p:idleConnectionTestPeriod="${idleConnectionTestPeriod}" />

jdbc:

minPoolSize=15
initalPollSize=25
maxPoolSize=60
#Give up waiting for a connection after this many milliseconds
checkoutTimeout=18000
maxIdleTime=3600
idleConnectionTestPeriod=300
maxStatements=100
numHelperThreads=15
acquireIncrement=10

    <!--session factory -->
    <bean id="sessionFactory"
            class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <property name="dataSource" ref="dataSource" />

            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                    <prop key="hibernate.show_sql">false</prop>
                    <prop key="hibernate.generate_statistics">false</prop>
                </props>
            </property>
            <property name="entityInterceptor" ref="auditInterceptor">
            </property>

        </bean>

    <!-- transaction manager -->
    <bean id="transactionManager"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory" />
        </bean>



    <!-- transaction interveptor -->

    <bean id="transactionInterceptor"
            class="org.springframework.transaction.interceptor.TransactionInterceptor">
            <property name="transactionManager" ref="transactionManager" />

        </bean>

        <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
            <property name="beanNames">
                <list>
                    <value>*Service</value>
                </list>
            </property>
            <property name="interceptorNames">
                <list>
                    <value>exceptionInterceptor</value>
                    <value>transactionInterceptor</value>
                </list>
            </property>
        </bean>

性能测试后我的内存没有被释放。所以当分析堆转储时出现以下错误

“org.apache.catalina.loader.WebappClassLoader @ 0x76000b8e8”加载的“org.hibernate.internal.SessionFactoryImpl”实例占用73,446,008 (32.66%)字节。内存在“org.apache.catalina.loader.WebappClassLoader @ 0x76000b8e8”加载的“org.hibernate.internal.util.collections.BoundedConcurrentHashMap$Segment[]”的一个实例中累积。

org.hibernate.internal.SessionFactoryImpl @ 0x7624efeb0 136 49,987,288 34.31% \org.hibernate.engine.query.spi.QueryPlanCache@0x7630b1250 32 47,674,176 32.72% .\org.hibernate.internal.util.collections.BoundedConcurrentHashMap @ 0x763259a58 48 47,554,336 32.64% ..\org.hibernate.internal.util.collections.BoundedConcurrentHashMap$Segment[32] @ 0x7632d1c60 144 47,554,288 32.64%

类名 |浅堆 |保留堆 |百分比

org.hibernate.internal.util.collections.BoundedConcurrentHashMap$Segment[32] @ 0x7632d1c60 | 144 | 47,554,288 | 32.64% |- org.hibernate.internal.util.collections.BoundedConcurrentHashMap$Segment @ 0x76325ac88 | 48 | 1,497,688 | 1.03% |- org.hibernate.internal.util.collections.BoundedConcurrentHashMap$Segment @ 0x76325ac58 | 48 | 1,631,272 | 1.12% | |- org.hibernate.internal.util.collections.BoundedConcurrentHashMap$LIRSHashEntry @ 0x768fd54c0 | 56 | 880 | 0.00% | | |- org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification @ 0x7671eb8e8 | 32 | 48 | 0.00% | | | '- org.hibernate.engine.query.spi.sql.NativeSQLQueryReturn[0] @ 0x768ff16d0 | 16 | 16 | 0.00% | | |- org.hibernate.engine.query.spi.NativeSQLQueryPlan @ 0x768ff1640 | 24 | 520 | 0.00%

| | |- java.lang.String @ 0x768ff1658 SELECT DISTINCT column FROM table WHERE column IN (94316) | 24 | 256 | 0.00%

请帮忙解决问题

【问题讨论】:

    标签: spring hibernate spring-mvc memory-leaks spring-transactions


    【解决方案1】:

    我们在堆中观察到一个查询。

    来自statusFlg='Y' and deleteFlg='N' and id="+autoGeneratedId'的表

    当我们将查询更改为

    来自表 statusFlg='Y' and deleteFlg='N' and id= :instanceid").setParameter("instanceId,autoGeneratedId)

    会话对象正在被垃圾收集。

    谁能详细解释一下

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 2013-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-05
      • 2016-02-21
      相关资源
      最近更新 更多