Spring Batch Tomcat内存泄漏

时间:2015-10-01 13:48:32

标签: spring tomcat spring-boot spring-batch

我用

Server Listening
Start processing
Start processing
Processing took 3007ms
Processing took 3005ms

在我的应用程序中,我有一个以下的Spring Batch配置:

Tomcat 8.0.26
Spring Boot 1.2.6.RELEASE
Spring 4.2.1.RELEASE
Spring Batch 3.0.5.RELEASE

这就是我的工作方式:

@Configuration
@EnableBatchProcessing
public class ReportJobConfig {

    public static final String REPORT_JOB_NAME = "reportJob";

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    private ReportService reportService;

    @Bean(name = REPORT_JOB_NAME)
    public Job reportJob() {
        //@formatter:off
        return jobBuilderFactory
                .get(REPORT_JOB_NAME)
                    .flow(createRequestStep())
                        .on("*").to(retriveInfoStep())
                            .on("*").to(notifyAdminStep())
                    .end().build();
        //@formatter:on
    }

    @Bean
    public Step createRequestStep() {
        return stepBuilderFactory.get("createRequest").tasklet(new CreateRequestTasklet(reportService)).build();
    }

    @Bean
    public Step retrivePHIStep() {
        return stepBuilderFactory.get("retriveInfo").tasklet(new RetriveInfoTasklet(reportService)).build();
    }

    @Bean
    public Step notifyAdminStep() {
        return stepBuilderFactory.get("notifyAdmin").tasklet(new NotifyAdminTasklet()).build();
    }

}

批次属性:

@Service
public class ReportJobServiceImpl implements ReportJobService {

    final static Logger logger = LoggerFactory.getLogger(ReportJobServiceImpl.class);

    @Autowired
    @Qualifier(ReportJobConfig.REPORT_JOB_NAME)
    private Job reportJob;

    @Autowired
    private JobLauncher jobLauncher;

    @Override
    public void runReportJob(String messageContent) throws JobExecutionAlreadyRunningException, JobRestartException,
            JobInstanceAlreadyCompleteException, JobParametersInvalidException {
        Map<String, JobParameter> parameters = new HashMap<>();
        JobParameter reportIdParameter = new JobParameter(messageContent);
        parameters.put(REPORT_ID, reportIdParameter);

        jobLauncher.run(reportJob, new JobParameters(parameters));
    }

}

我将此应用程序部署到Tomcat 8,执行一些作业,然后通过Tomcat Web应用程序管理器取消部署应用程序。

使用Java VisualVM工具,我比较了之前和之后的内存快照,并发现内存中仍存在大量Spring Batch(batch.jdbc.driver=com.mysql.jdbc.Driver batch.jdbc.url=jdbc:mysql://localhost/database batch.jdbc.user=user batch.jdbc.password=password batch.jdbc.testWhileIdle=true batch.jdbc.validationQuery=SELECT 1 batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-mysql.sql batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql batch.business.schema.script=classpath:/business-schema-mysql.sql batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer batch.database.incrementer.parent=columnIncrementerParent batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.grid.size=50 batch.jdbc.pool.size=6 batch.verify.cursor.position=true batch.isolationlevel=ISOLATION_SERIALIZABLE batch.table.prefix=BATCH_ )相关对象:

enter image description here

另外,我运行了1000 org.springframework.batch.*并在我的机器上消耗了大量内存..我现在不知道会出现什么问题..

可能导致此问题的原因是什么?

已更新

我从AWS SQS队列中消耗了大约1000条消息。我的JMS侦听器配置为一次使用1条消息。在执行期间,我有一个以下堆直方图:

enter image description here

我真的不明白为什么我需要在内存中有7932个StepExecution ..或5285个JobExecution对象的实例。我的错误在哪里?

0 个答案:

没有答案