Skip to content

Provide properties to set the number of threads of spring TaskScheduler #1397

Closed

Description

@m11y

By default, it use Executors.newSingleThreadScheduledExecutor() to create executor, and it only have one thread.
But when I config the executor manually:

    @Bean
    public ConcurrentTaskScheduler taskScheduler() {
        ConcurrentTaskScheduler taskScheduler = new ConcurrentTaskScheduler();
        taskScheduler.setScheduledExecutor(executorService());
        return taskScheduler;
    }

    @Bean
    public ScheduledExecutorService executorService() {
        ScheduledExecutorFactoryBean bean = new ScheduledExecutorFactoryBean();
        bean.setThreadNamePrefix("schedule");
        bean.setPoolSize(10);
        return bean.getObject();
    }

Exception occurs:

Exception in thread "main" java.lang.IllegalStateException: More than one TaskScheduler and/or ScheduledExecutorService  exist within the context.

Activity

  1. changed the title [-]Is there any way to set the number of threads of spring TaskScheduler?[/-] [+]Is there any convenient way to set the number of threads of spring TaskScheduler?[/+] on Aug 19, 2014
  2. m11y commented on Aug 19, 2014

    @m11y
    Author

    When I config as follow:

        @Bean
        public ScheduledExecutorFactoryBean executorService() {
            ScheduledExecutorFactoryBean bean = new ScheduledExecutorFactoryBean();
            bean.setThreadNamePrefix("schedule-");
            bean.setPoolSize(10);
            return bean;
        }
    

    It, works.
    However, is there any convenient way to config executor pool size. like:

    spring.datasource.max-active: 20
    

    to config:

    spring.scheduling.poolSize: 20
    
  3. snicoll commented on Aug 19, 2014

    @snicoll
    Member

    There is no explicit scheduling support in Spring boot if that's what your question is. Are you saying we should provide an easier way to configure the executor service used by @EnableScheduling?

  4. m11y commented on Aug 19, 2014

    @m11y
    Author

    @snicoll yes, my English is very poor.

  5. changed the title [-]Is there any convenient way to set the number of threads of spring TaskScheduler?[/-] [+]Provide properties to set the number of threads of spring TaskScheduler[/+] on Aug 21, 2014
  6. philwebb commented on Mar 22, 2018

    @philwebb
    Member

    Duplicates #1563.

  7. added
    status: duplicate
    on Mar 22, 2018
  8. snicoll commented on Aug 6, 2018

    @snicoll
    Member

    That's not a duplicate of #1563 - #1563 is about TaskExecutor and this one is about TaskScheduler. Those are two completely separate contracts.

  9. reopened this on Aug 6, 2018
  10. added
    for: team-attention
    and removed
    status: duplicate
    on Aug 6, 2018
  11. self-assigned this
    on Aug 8, 2018
  12. added a commit that references this issue on Aug 8, 2018
  13. removed
    for: team-attention
    on Aug 8, 2018
  14. added this to the 2.1.0.M2 milestone on Aug 8, 2018
  15. modified the milestones: 2.1.0.M2, Backlog on Aug 8, 2018
  16. modified the milestones: Backlog, 2.1.0.M2 on Aug 16, 2018
  17. added a commit that references this issue on May 7, 2022
    bb63ce9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions