Skip to content

Multiple TaskSchedulers to be supported with @Scheduled [SPR-16271] #20818

New issue

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

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

Already on GitHub? # to your account

Closed
spring-projects-issues opened this issue Dec 6, 2017 · 8 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Peter Szanto opened SPR-16271 and commented

I would like to have multiple scheduled tasks in my application, with multiple their pool size, thread name and some as daemon. I can customize these properties using a TaskScheduler, but in an single application I can have only one TaskScheduler. It would be nice if I could define multiple schedulers and refer them in the @Scheduled annotation similar as I can refer cache name in the @Cacheable annotation. There could be even something similar to @CacheConfig so class level settings for multiple scheduled definitions could be configured


Affects: 4.3.13

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.x Backlog milestone Jan 11, 2019
@Axinet
Copy link

Axinet commented Sep 17, 2020

It is also worth to mention that @Async annotation also working on executors has already such option since 3.1.2. I am really surprised that @Scheduled annotation has been skipped then.

@jhoeller jhoeller self-assigned this Sep 17, 2020
@jhoeller jhoeller changed the title Multiple TaskSchedulers to be supported with @Schedlued [SPR-16271] Multiple TaskSchedulers to be supported with @Scheduled [SPR-16271] Sep 17, 2020
@warrior107
Copy link

Hi,
Is someone working on this? Or is there a workaround for the time being?

@idkw
Copy link

idkw commented Nov 4, 2020

Hello, I also need this.
Current workaround is to call an @async method from a @scheduled method but this is very confusing to maintain

@idkw
Copy link

idkw commented Nov 4, 2020

Another workaround but it would be simpler for it to be supported directly via the annotation.
The @scheduled annotation processor in spring builds a ScheduledMethodRunnable instance as the Runnable passed into the TaskScheduler so theorically we could build a TaskScheduler wrapper that plays the role of a dispatcher that uses the method name to select which actual TaskScheduler to use.

But again, a native support would be very much appreciated

image

From : org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor
image

@dantebarba
Copy link

@idkw great answer!. Can you post the generic dispatcher code into some gist? Thanks.

@idkw
Copy link

idkw commented Aug 19, 2021

@idkw great answer!. Can you post the generic dispatcher code into some gist? Thanks.

I don't have any code, this was just an idea of a possible workaround

@marwin1991
Copy link

any progres ?

@jhoeller jhoeller modified the milestones: 6.x Backlog, 6.1.0-M3, 6.1.0-M2 Jul 5, 2023
@jhoeller
Copy link
Contributor

jhoeller commented Jul 8, 2023

This is finally coming in 6.1 now: with a scheduler attribute on @Scheduled and supporting infrastructure underneath, including a qualifier value on SchedulingAwareRunnable and ScheduledMethodRunnable. Note that this is analogous to the transactionManager attribute on @Transactional, even more so than the qualifier value on @Async.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants