Hibernate内存泄漏-BoundedConcurrentHashMap

时间:2017-04-05 17:47:05

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

请帮助解决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%

请帮助解决问题

1 个答案:

答案 0 :(得分:0)

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

来自表格,其中statusFlg ='Y'且deleteFlg ='N'且id =“+ autoGeneratedId

当我们将查询更改为

表中statusFlg ='Y'和deleteFlg ='N'和id =:instanceid“)。setParameter(”instanceId,autoGeneratedId)

会话对象正在收集垃圾。

有人可以在deail中解释