Skip to content

Commit 35610a5

Browse files
committed
Expose cancel(mayInterruptIfRunning) variant in ScheduledTask
Closes gh-28233
1 parent acf2955 commit 35610a5

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2022 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.
@@ -29,6 +29,7 @@
2929
* @see ScheduledTaskRegistrar#scheduleCronTask(CronTask)
3030
* @see ScheduledTaskRegistrar#scheduleFixedRateTask(FixedRateTask)
3131
* @see ScheduledTaskRegistrar#scheduleFixedDelayTask(FixedDelayTask)
32+
* @see ScheduledFuture
3233
*/
3334
public final class ScheduledTask {
3435

@@ -54,11 +55,24 @@ public Task getTask() {
5455

5556
/**
5657
* Trigger cancellation of this scheduled task.
58+
* <p>This variant will force interruption of the task if still running.
59+
* @see #cancel(boolean)
5760
*/
5861
public void cancel() {
62+
cancel(true);
63+
}
64+
65+
/**
66+
* Trigger cancellation of this scheduled task.
67+
* @param mayInterruptIfRunning whether to force interruption of the task
68+
* if still running (specify {@code false} to allow the task to complete)
69+
* @since 5.3.18
70+
* @see ScheduledFuture#cancel(boolean)
71+
*/
72+
public void cancel(boolean mayInterruptIfRunning) {
5973
ScheduledFuture<?> future = this.future;
6074
if (future != null) {
61-
future.cancel(true);
75+
future.cancel(mayInterruptIfRunning);
6276
}
6377
}
6478

0 commit comments

Comments
 (0)