Skip to content

Commit 9a856c0

Browse files
committed
Clarify @EnableScheduling javadoc
It is now advised that destroyMethod="shutdown" should be used on @bean methods returning an ExecutorService. Issue: SPR-9280
1 parent 283c1b9 commit 9a856c0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -105,12 +105,16 @@
105105
* taskRegistrar.setScheduler(taskExecutor());
106106
* }
107107
*
108-
* @Bean
108+
* @Bean(destroyMethod="shutdown")
109109
* public Executor taskExecutor() {
110110
* return Executors.newScheduledThreadPool(100);
111111
* }
112112
* }</pre>
113113
*
114+
* Note in the example above the use of {@code @Bean(destroyMethod="shutdown")}. This
115+
* ensures that the task executor is properly shut down when the Spring application
116+
* context itself is closed.
117+
*
114118
* Implementing {@code SchedulingConfigurer} also allows for fine-grained
115119
* control over task registration via the {@code ScheduledTaskRegistrar}.
116120
* For example, the following configures the execution of a particular bean
@@ -133,7 +137,7 @@
133137
* );
134138
* }
135139
*
136-
* &#064;Bean
140+
* &#064;Bean(destroyMethod="shutdown")
137141
* public Executor taskScheduler() {
138142
* return Executors.newScheduledThreadPool(42);
139143
* }

0 commit comments

Comments
 (0)