Skip to content

Scheduled/JmsListenerAnnotationBeanPostProcessor needlessly scans every scoped instance [SPR-12189] #16803

@spring-projects-issues

Description

@spring-projects-issues

Jean-Baptiste Nizet opened SPR-12189 and commented

ScheduledAnnotationBeanPostProcessor scans the methods of all the beans created by Spring for @Scheduled annotations. But this also includes, in a web application, all the request- and session-scoped beans, created long after the context has been started and the tasks have been scheduled.
It thus has two implications:

  • if a Scheduled annotation is placed on a request-scoped bean (stupid, I know), a new Runnable is created at each request, referencing the request-scoped bean, and placed in a list of the registrar, which causes a big memory leak
  • several classes are needlessly scanned at each request for nothing if request-scoped beans are used in the application, consituting a loss of performance, that grows with the number of request-scoped beans used.

A flag could be set to true as soon as afterSingletonsInstantiated() has been called, and the postProcessAfterInitialization() method would do nothing if this flag is set.


Affects: 3.2.11, 4.0.7, 4.1 GA

Issue Links:

Referenced from: commits 58b22ce, 37da706, d2e8b7e

Backported to: 4.0.8, 3.2.12

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions