What is the default scheduler pool size in spring-boot?

前端 未结 5 1081
栀梦
栀梦 2020-12-05 09:53

I\'m using spring-boot and @Scheduled annotation to execute some tasks.

How can I find out what the default pool size of scheduled tasks is

5条回答
  •  爱一瞬间的悲伤
    2020-12-05 10:11

    Yes, all @Scheduled methods share a single thread by default. It is possible to override this behavior by defining a @Configuration such as this:

    @Configuration
    public class SchedulingConfigurerConfiguration implements SchedulingConfigurer {
    
        @Override
        public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
            ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
            taskScheduler.setPoolSize(100);
            taskScheduler.initialize();
            taskRegistrar.setTaskScheduler(taskScheduler);
        }
    }
    

    This example ensures that all @Scheduled methods share a thread pool of size 100.

提交回复
热议问题