How to control the number of parallel Spring Batch jobs

后端 未结 2 581
有刺的猬
有刺的猬 2020-12-31 22:55

I have a report generating application. As preparation of such reports is heavyweight, they are prepared asynchronously with Spring Batch. Requests for such reports are crea

相关标签:
2条回答
  • 2020-12-31 23:34

    SimpleAsyncTaskExecutor isn't recommended for heavy use since it spawns a new thread with each task. It also does not support more robust concepts like thread pooling and queueing of tasks.

    If you take a look at the ThreadPoolTaskExecutor, it supports a more robust task execution paradigm with things like queueing of tasks and using a thread pool instead of spawning random, un-reused threads.

    You can read more about the ThreadPoolTaskExecutor in the javadoc here: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.html

    0 讨论(0)
  • 2020-12-31 23:42

    That helped, many thanks. After replacing SimpleAsyncTaskExecutor I have exactly what I need. Code:

    @Bean
    public TaskExecutor jobLauncherTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setMaxPoolSize(executorsPoolSize);
        executor.setCorePoolSize(executorsPoolSize);
        return executor;
    }
    

    Thanks f

    0 讨论(0)
提交回复
热议问题