diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java index bb939d5024c..d4a2305023c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,12 +105,16 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * taskRegistrar.setScheduler(taskExecutor()); * } * - * @Bean + * @Bean(destroyMethod="shutdown") * public Executor taskExecutor() { * return Executors.newScheduledThreadPool(100); * } * } * + * Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}. This + * ensures that the task executor is properly shut down when the Spring application + * context itself is closed. + * * Implementing {@code SchedulingConfigurer} also allows for fine-grained * control over task registration via the {@code ScheduledTaskRegistrar}. * For example, the following configures the execution of a particular bean @@ -133,7 +137,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; * ); * } * - * @Bean + * @Bean(destroyMethod="shutdown") * public Executor taskScheduler() { * return Executors.newScheduledThreadPool(42); * }