2015-09-22 47 views
0

我寫了一個使用JPA + Hibernate模型進行讀寫操作的spring批處理應用程序。Spring批處理中由於HibernateSessionImpl導致內存泄漏

由於hibernateSessionImpl對象,我得到OutOfmemory錯誤。

我使用JPA實體管理器工廠:org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean

在spring.xml配置一個singleton bean

錯誤:

java.lang.OutOfMemoryError 
at java.util.HashMap.createHashedEntry(HashMap.java:650) 
at java.util.HashMap.putImpl(HashMap.java:629) 
at java.util.HashMap.put(HashMap.java:605) 
at org.hibernate.event.def.AbstractFlushingEventListener.postFlush(AbstractFlushingEventListener.java:366) 
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52) 
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) 
at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:960) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240) 
at $Proxy43.flush(Unknown Source) 
at com.bunge.portal.core.dao.jpa.RssGenericDaoJpaImpl.create(RssGenericDaoJpaImpl.java:200) 
at com.bunge.portal.rss.repository.RssFeedContentCacheRepositoryImpl.create(RssFeedContentCacheRepositoryImpl.java:17) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
at $Proxy44.create(Unknown Source) 
at com.bunge.portal.rss.service.RssFeedServiceImpl.createRssFeedContentCache(RssFeedServiceImpl.java:46) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
at java.lang.reflect.Method.invoke(Method.java:600) 
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
15:22:08,023 ERROR AbstractStep:212 - Encountered an error executing the step 
org.springframework.batch.core.JobExecutionException: Partition handler returned an unsuccessful step 
at org.springframework.batch.core.partition.support.PartitionStep.doExecute(PartitionStep.java:110) 
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) 
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) 
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) 
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) 
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) 
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) 
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) 
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) 
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) 
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) 
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) 
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) 
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) 
+0

並添加完整的堆棧跟蹤。 – Jens

+0

我在調用create()方法時出錯。 –

+0

它看起來不像內存泄漏。你的應用程序只需要更多的內存。 – Jens

回答

0

的問題是,我們在一個被獲取8000條記錄的查詢並僅使用第一條記錄。由於表中記錄的數量較少,批處理已成功運行,但隨着時間的推移,記錄總數過多,並且溢出了堆內存,我更改了查詢以僅抓取一條記錄,最後一條記錄工作正常。 ...

感謝您的幫助大家..!