Skip to content
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

@Scheduled methods in @Lazy beans are not scheduled [SPR-12872] #17470

Closed
spring-issuemaster opened this issue Mar 31, 2015 · 2 comments
Closed

@Scheduled methods in @Lazy beans are not scheduled [SPR-12872] #17470

spring-issuemaster opened this issue Mar 31, 2015 · 2 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Mar 31, 2015

Ivan Bovin opened SPR-12872 and commented

If we have a @Scheduled method in a @Lazy bean, it will be added to ScheduledTaskRegistrar (e.g. using a addFixedDelayTask method) but not scheduled in the taskScheduler.

Example:

@Lazy
@Component
public class SampleBean {
    @Scheduled(fixedDelay = 500)
    public void task() {
        System.out.println("-");
    }
}

Affects: 4.1.5

Issue Links:

  • #16830 ScheduledAnnotationBeanPostProcessor should unregister tasks on destruction of individual beans
  • #22119 @Scheduled methods in @Lazy beans are not scheduled
  • #19230 Performance regression when scheduling is enabled and context contains URL beans
  • #18739 Improve reference documentation for Task Execution and Scheduling about bean scopes

Referenced from: commits ab478d1

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Mar 31, 2015

Juergen Hoeller commented

This is unfortunately a known limitation at this point: @Scheduled only really works on non-lazy singletons. We'll revisit this for 4.2.

Juergen

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented May 4, 2016

Juergen Hoeller commented

As of 4.3 RC2, ScheduledAnnotationBeanPostProcessor features a revised registration mechanism capable of tracking individual bean instances, both on creation for beans of any scope and on destruction of each individual bean. In other words, @Scheduled works on any Spring-managed bean now, not just on non-lazy singleton beans anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.