2 minutes estimated read time

Scheduled tasks

A scheduled task is essentially like a repeatable task but a lot slimmer.
Just like repeatable tasks, scheduled tasks run on your server's scheduler.

You should use scheduled tasks only if you need a simpler version of a repeatable task.
Scheduled tasks cannot be paused or stopped and will run from the moment your server starts to the moment it stops.
E.g., use it to spawn particle effects for players in your lobby, etc.

A scheduled task must always be declared as a method annotated with @VitalScheduled inside a Spring bean (Any class annotated with @Component internally).

MyComponent.java
@Component
class MyComponent {
  @VitalScheduled(initialDelay = 1, fixedDelay = 5, timeUnit = TimeUnit.SECONDS)
  public void myScheduledTask() {
    for (final var player : Bukkit.getOnlinePlayers()) {
      player.sendMessage("myScheduledTask ticked.");
    }
  }
}

When this scheduled task is started, it will initially have a delay of 1 second and will then repeatedly be called every 5 seconds.

Found an issue?

Help us improve the documentation by reporting typos, missing information, or anything confusing.

Don't worry, we will auto-fill most of the annoying fields.

Create GitHub issue

This site and the Vital framework were built with ❤️ by Mike Neumann