Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
m11y opened this issue Aug 19, 2014 · 5 comments
Closed

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

m11y opened this issue Aug 19, 2014 · 5 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@m11y
Copy link

m11y commented Aug 19, 2014

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.
@m11y m11y 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? Aug 19, 2014
@m11y
Copy link
Author

m11y commented Aug 19, 2014

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

@snicoll
Copy link
Member

snicoll commented Aug 19, 2014

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?

@m11y
Copy link
Author

m11y commented Aug 19, 2014

@snicoll yes, my English is very poor.

@philwebb philwebb 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 Aug 21, 2014
@philwebb
Copy link
Member

philwebb commented Mar 22, 2018

Duplicates #1563.

@philwebb philwebb added the status: duplicate A duplicate of another issue label Mar 22, 2018
@snicoll
Copy link
Member

snicoll commented Aug 6, 2018

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

@snicoll snicoll reopened this Aug 6, 2018
@snicoll snicoll added for: team-attention An issue we'd like other members of the team to review and removed status: duplicate A duplicate of another issue labels Aug 6, 2018
@snicoll snicoll self-assigned this Aug 8, 2018
snicoll added a commit to snicoll/spring-boot that referenced this issue Aug 8, 2018
@snicoll snicoll removed the for: team-attention An issue we'd like other members of the team to review label Aug 8, 2018
@snicoll snicoll added this to the 2.1.0.M2 milestone Aug 8, 2018
@philwebb philwebb modified the milestones: 2.1.0.M2, Backlog Aug 8, 2018
@snicoll snicoll modified the milestones: Backlog, 2.1.0.M2 Aug 16, 2018
humaolin pushed a commit to humaolin/spring-boot that referenced this issue May 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants