问题
running latest Spring 4.1.0 and spring batch 3.0.1
Uisng
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager"/>
I have a job that executes every few seconds, it's a very basic ETL job, check if Db has some data transforms and pushes to another system. If nothing to be done it tries on next run.
I have noticed that memory consumption keeps going up on HasMap objects even if the job has nothing to do. So is MapJobRepositoryFactoryBean keeping state in memory? I assume it is... I tried with the persisted job repository also and the memory consumption stays low.
For operational purposes and simplicity don't care about the job history and previous states of jobs so I don't really need a persisted repository. I just want something to run every few seconds.
So is there another way to clean up the state of MapJobRepositoryFactoryBean automatically or not to track full state and keep memory low?
回答1:
Yes, the map based job repository will keep the state in memory for ever. As the javadoc states (http://docs.spring.io/spring-batch/apidocs/org/springframework/batch/core/repository/support/MapJobRepositoryFactoryBean.html), that JobRepository implementation really isn't intended for production use. If you want to have a memory based JobRepository that you can clean up, use an in memory database and execute clean up scripts periodically.
来源:https://stackoverflow.com/questions/26302304/does-spring-batch-job-repository-with-resource-less-trx-manager-keep-state-in-me