Skip to content

Commit

Permalink
Expose cancel(mayInterruptIfRunning) variant in ScheduledTask
Browse files Browse the repository at this point in the history
Closes gh-28233
  • Loading branch information
jhoeller committed Mar 25, 2022
1 parent acf2955 commit 35610a5
Showing 1 changed file with 16 additions and 2 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2022 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.
Expand Down Expand Up @@ -29,6 +29,7 @@
* @see ScheduledTaskRegistrar#scheduleCronTask(CronTask)
* @see ScheduledTaskRegistrar#scheduleFixedRateTask(FixedRateTask)
* @see ScheduledTaskRegistrar#scheduleFixedDelayTask(FixedDelayTask)
* @see ScheduledFuture
*/
public final class ScheduledTask {

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

/**
* Trigger cancellation of this scheduled task.
* <p>This variant will force interruption of the task if still running.
* @see #cancel(boolean)
*/
public void cancel() {
cancel(true);
}

/**
* Trigger cancellation of this scheduled task.
* @param mayInterruptIfRunning whether to force interruption of the task
* if still running (specify {@code false} to allow the task to complete)
* @since 5.3.18
* @see ScheduledFuture#cancel(boolean)
*/
public void cancel(boolean mayInterruptIfRunning) {
ScheduledFuture<?> future = this.future;
if (future != null) {
future.cancel(true);
future.cancel(mayInterruptIfRunning);
}
}

Expand Down

0 comments on commit 35610a5

Please sign in to comment.