Skip to content

Clarify @EnableScheduling javadoc re ExecutorService shutdown [SPR-9280] #13918

@spring-projects-issues

Description

@spring-projects-issues

Grzegorz Grzybek opened SPR-9280 and commented

Javadoc for @EnableScheduling has the following code example:

 @Configuration
 @EnableScheduling
 public class AppConfig implements SchedulingConfigurer {
     @Override
     public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
         taskRegistrar.setScheduler(taskExecutor());
     }

     @Bean
     public Executor taskExecutor() {
         return Executors.newScheduledThreadPool(100);
     }
 }

With such @Bean definition (taskExecutor), the returned bean cannot be properly destroyed while closing the appcontext - returned TaskSheduler have "shutdown" method, but it cannot be invoked using "(inferred)" mechanism. So with e.g., web application it causes memory leaks.

Please either

  • change "taskExecutor" definition to return org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler, or
  • use @Bean(destroyMethod = "shutdown")

one more thing - I have strange issues with:

@Bean(destroyMethod = "shutdown")
public Executor springTaskScheduler()
{
  return Executors.newScheduledThreadPool(10);
}

because although shutdown() is called, some classes from Spring (in heap dump) appear to have been on "native stack" (e.g., org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator) - more on this on Spring Forum (soon)

regards
Grzegorz Grzybek


Affects: 3.1.1

Referenced from: commits 9a856c0, 1380d05

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions