1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2016 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .scheduling ;
18
18
19
+ import java .time .Duration ;
20
+ import java .time .Instant ;
19
21
import java .util .Date ;
20
22
import java .util .concurrent .ScheduledFuture ;
21
23
34
36
* and adding extended trigger capabilities.
35
37
*
36
38
* <p>This interface is roughly equivalent to a JSR-236
37
- * {@code ManagedScheduledExecutorService} as supported in Java EE 6
38
- * environments. However, at the time of the Spring 3.0 release, the
39
- * JSR-236 interfaces have not been released in official form yet.
39
+ * {@code ManagedScheduledExecutorService} as supported in Java EE 7
40
+ * environments but aligned with Spring's {@code TaskExecutor} model.
40
41
*
41
42
* @author Juergen Hoeller
42
43
* @since 3.0
@@ -64,6 +65,23 @@ public interface TaskScheduler {
64
65
*/
65
66
ScheduledFuture <?> schedule (Runnable task , Trigger trigger );
66
67
68
+ /**
69
+ * Schedule the given {@link Runnable}, invoking it at the specified execution time.
70
+ * <p>Execution will end once the scheduler shuts down or the returned
71
+ * {@link ScheduledFuture} gets cancelled.
72
+ * @param task the Runnable to execute whenever the trigger fires
73
+ * @param startTime the desired execution time for the task
74
+ * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
75
+ * @return a {@link ScheduledFuture} representing pending completion of the task
76
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
77
+ * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
78
+ * @since 5.0
79
+ * @see #schedule(Runnable, Date)
80
+ */
81
+ default ScheduledFuture <?> schedule (Runnable task , Instant startTime ) {
82
+ return schedule (task , Date .from (startTime ));
83
+ }
84
+
67
85
/**
68
86
* Schedule the given {@link Runnable}, invoking it at the specified execution time.
69
87
* <p>Execution will end once the scheduler shuts down or the returned
@@ -77,6 +95,25 @@ public interface TaskScheduler {
77
95
*/
78
96
ScheduledFuture <?> schedule (Runnable task , Date startTime );
79
97
98
+ /**
99
+ * Schedule the given {@link Runnable}, invoking it at the specified execution time
100
+ * and subsequently with the given period.
101
+ * <p>Execution will end once the scheduler shuts down or the returned
102
+ * {@link ScheduledFuture} gets cancelled.
103
+ * @param task the Runnable to execute whenever the trigger fires
104
+ * @param startTime the desired first execution time for the task
105
+ * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
106
+ * @param period the interval between successive executions of the task
107
+ * @return a {@link ScheduledFuture} representing pending completion of the task
108
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
109
+ * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
110
+ * @since 5.0
111
+ * @see #scheduleAtFixedRate(Runnable, Date, long)
112
+ */
113
+ default ScheduledFuture <?> scheduleAtFixedRate (Runnable task , Instant startTime , Duration period ) {
114
+ return scheduleAtFixedRate (task , Date .from (startTime ), period .toMillis ());
115
+ }
116
+
80
117
/**
81
118
* Schedule the given {@link Runnable}, invoking it at the specified execution time
82
119
* and subsequently with the given period.
@@ -87,11 +124,28 @@ public interface TaskScheduler {
87
124
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
88
125
* @param period the interval between successive executions of the task (in milliseconds)
89
126
* @return a {@link ScheduledFuture} representing pending completion of the task
90
- * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
127
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
91
128
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
92
129
*/
93
130
ScheduledFuture <?> scheduleAtFixedRate (Runnable task , Date startTime , long period );
94
131
132
+ /**
133
+ * Schedule the given {@link Runnable}, starting as soon as possible and
134
+ * invoking it with the given period.
135
+ * <p>Execution will end once the scheduler shuts down or the returned
136
+ * {@link ScheduledFuture} gets cancelled.
137
+ * @param task the Runnable to execute whenever the trigger fires
138
+ * @param period the interval between successive executions of the task
139
+ * @return a {@link ScheduledFuture} representing pending completion of the task
140
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
141
+ * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
142
+ * @since 5.0
143
+ * @see #scheduleAtFixedRate(Runnable, long)
144
+ */
145
+ default ScheduledFuture <?> scheduleAtFixedRate (Runnable task , Duration period ) {
146
+ return scheduleAtFixedRate (task , period .toMillis ());
147
+ }
148
+
95
149
/**
96
150
* Schedule the given {@link Runnable}, starting as soon as possible and
97
151
* invoking it with the given period.
@@ -114,22 +168,59 @@ public interface TaskScheduler {
114
168
* @param task the Runnable to execute whenever the trigger fires
115
169
* @param startTime the desired first execution time for the task
116
170
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
117
- * @param delay the delay between the completion of one execution and the start
118
- * of the next (in milliseconds)
171
+ * @param delay the delay between the completion of one execution and the start of the next
119
172
* @return a {@link ScheduledFuture} representing pending completion of the task
120
173
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
121
174
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
175
+ * @since 5.0
176
+ * @see #scheduleWithFixedDelay(Runnable, Date, long)
122
177
*/
123
- ScheduledFuture <?> scheduleWithFixedDelay (Runnable task , Date startTime , long delay );
178
+ default ScheduledFuture <?> scheduleWithFixedDelay (Runnable task , Instant startTime , Duration delay ) {
179
+ return scheduleWithFixedDelay (task , Date .from (startTime ), delay .toMillis ());
180
+ }
124
181
125
182
/**
126
- * Schedule the given {@link Runnable}, starting as soon as possible and
127
- * invoking it with the given delay between the completion of one execution
183
+ * Schedule the given {@link Runnable}, invoking it at the specified execution time
184
+ * and subsequently with the given delay between the completion of one execution
128
185
* and the start of the next.
129
186
* <p>Execution will end once the scheduler shuts down or the returned
130
187
* {@link ScheduledFuture} gets cancelled.
131
188
* @param task the Runnable to execute whenever the trigger fires
132
- * @param delay the interval between successive executions of the task (in milliseconds)
189
+ * @param startTime the desired first execution time for the task
190
+ * (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
191
+ * @param delay the delay between the completion of one execution and the start of the next
192
+ * (in milliseconds)
193
+ * @return a {@link ScheduledFuture} representing pending completion of the task
194
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
195
+ * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
196
+ */
197
+ ScheduledFuture <?> scheduleWithFixedDelay (Runnable task , Date startTime , long delay );
198
+
199
+ /**
200
+ * Schedule the given {@link Runnable}, starting as soon as possible and invoking it with
201
+ * the given delay between the completion of one execution and the start of the next.
202
+ * <p>Execution will end once the scheduler shuts down or the returned
203
+ * {@link ScheduledFuture} gets cancelled.
204
+ * @param task the Runnable to execute whenever the trigger fires
205
+ * @param delay the delay between the completion of one execution and the start of the next
206
+ * @return a {@link ScheduledFuture} representing pending completion of the task
207
+ * @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
208
+ * for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
209
+ * @since 5.0
210
+ * @see #scheduleWithFixedDelay(Runnable, long)
211
+ */
212
+ default ScheduledFuture <?> scheduleWithFixedDelay (Runnable task , Duration delay ) {
213
+ return scheduleWithFixedDelay (task , delay .toMillis ());
214
+ }
215
+
216
+ /**
217
+ * Schedule the given {@link Runnable}, starting as soon as possible and invoking it with
218
+ * the given delay between the completion of one execution and the start of the next.
219
+ * <p>Execution will end once the scheduler shuts down or the returned
220
+ * {@link ScheduledFuture} gets cancelled.
221
+ * @param task the Runnable to execute whenever the trigger fires
222
+ * @param delay the delay between the completion of one execution and the start of the next
223
+ * (in milliseconds)
133
224
* @return a {@link ScheduledFuture} representing pending completion of the task
134
225
* @throws org.springframework.core.task.TaskRejectedException if the given task was not accepted
135
226
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
0 commit comments