Package org.springframework.scheduling.config

# Class ScheduledTask

java.lang.Object
org.springframework.scheduling.config.ScheduledTask

public final class ScheduledTask extends Object
A representation of a scheduled task at runtime, used as a return value for scheduling methods.

Since:
  4.3
Author:
  Juergen Hoeller, Brian Clozel
See Also:
  - `ScheduledTaskRegistrar.scheduleCronTask(CronTask)`
  - `ScheduledTaskRegistrar.scheduleFixedRateTask(FixedRateTask)`
  - `ScheduledTaskRegistrar.scheduleFixedDelayTask(FixedDelayTask)`
  - `ScheduledFuture`

## Method Summary

Modifier and Type
Method
Description
`void`
`cancel()`
Trigger cancellation of this scheduled task.
`void`
`cancel(boolean mayInterruptIfRunning)`
Trigger cancellation of this scheduled task.
`Task`
`getTask()`
Return the underlying task (typically a `CronTask`, `FixedRateTask` or `FixedDelayTask`).
`Instant`
`nextExecution()`
Return the next scheduled execution of the task, or `null` if the task has been cancelled or no new execution is scheduled.
`String`
`toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Method Details

### getTask

public Task getTask()
Return the underlying task (typically a `CronTask`, `FixedRateTask` or `FixedDelayTask`).

Since:
  5.0.2

### cancel

public void cancel()
Trigger cancellation of this scheduled task.

This variant will force interruption of the task if still running.

See Also:
  - `cancel(boolean)`

### cancel

public void cancel(boolean mayInterruptIfRunning)
Trigger cancellation of this scheduled task.

Parameters:
  `mayInterruptIfRunning` - whether to force interruption of the task if still running (specify `false` to allow the task to complete)
Since:
  5.3.18
See Also:
  - `Future.cancel(boolean)`

### nextExecution

@Nullable public Instant nextExecution()
Return the next scheduled execution of the task, or `null` if the task has been cancelled or no new execution is scheduled.

Since:
  6.2

### toString

public String toString()

Overrides:
  `toString` in class `Object`