From 9a856c09f322b8ae821ff5e6a86dc0b0aeaf618d Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Mon, 14 May 2012 12:15:42 +0300 Subject: [PATCH] Clarify @EnableScheduling javadoc It is now advised that destroyMethod="shutdown" should be used on @Bean methods returning an ExecutorService. Issue: SPR-9280 --- .../scheduling/annotation/EnableScheduling.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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); * }