Skip to content

Closing an ApplicationContext leads to Exception at ExecutorServiceAdapter #29892

Closed
@Spunc

Description

@Spunc

Affects: 6.0.4

Problem

When an ApplicationContext with a org.springframework.core.task.support.ExecutorServiceAdapter bean present is closed, the shutdown() method of ExecutorServiceAdapter gets called which throws an IllegalStateException leading to a warning:

Jan. 27, 2023 1:41:44 PM org.springframework.beans.factory.support.DisposableBeanAdapter invokeCustomDestroyMethod
WARNUNG: Custom destroy method 'shutdown' on bean with name 'executorService' threw an exception: java.lang.IllegalStateException: Manual shutdown not supported - ExecutorServiceAdapter is dependent on an external lifecycle

Steps to reproduce

  1. Configure an ApplicationContext with a ExecutorServiceAdapter bean
@Configuration
public class Config {

    @Bean
    public TaskExecutor taskExecutor() {
        return new ThreadPoolTaskExecutor();
    }

    @Bean
    public ExecutorService executorService(TaskExecutor taskExecutor) {
        return new ExecutorServiceAdapter(taskExecutor);
    }
}
  1. Start and stop the ApplicationContext:
  public class Main {

      public static void main(String[] args) {
          ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class);
          applicationContext.getBean("executorService", ExecutorService.class);
          applicationContext.close();
      }
  }

Or have a look at a sample project that reproduces the error.

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions