IntelliJ IDEA 2024.2 Help

Scheduled Tasks

Scheduled tasks in Spring allow you to perform repeated operations or execute specific code at defined intervals or schedules.

IntelliJ IDEA provides the following tools to make it easier to work with scheduled tasks:

Cron expression support

IntelliJ IDEA provides coding assistance and human-readable descriptions for cron expressions in scheduled Spring, Quarkus, and Micronaut services.

Enable the Cron Expressions plugin

This functionality relies on the Cron Expressions plugin, which is bundled and enabled in IntelliJ IDEA by default. If the relevant features are not available, make sure that you did not disable the plugin.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Installed tab, find the Cron Expressions plugin, and select the checkbox next to the plugin name.

When you use cron expressions in scheduled tasks, the cron expression language is injected providing you with corresponding coding assistance, such as completion and syntax validation. Human-readable explanations appear in inlay hints, making it easier to quickly understand and verify cron expressions.

Cron expression explanations

To get a list of cron expression examples, press Ctrl+Space after the cron keyword.

Cron expression examples

Spring Scheduled methods

If you want to debug a scheduled method, you don't have to wait for it to start: IntelliJ IDEA lets you trigger it right away using the dedicated gutter icon.

Enable scheduled debugger

To trigger scheduled methods, we have to add a JVMTI agent to your application. It will be suggested when you click the Trigger the @Scheduled method icon , but you can also add it manually in the Spring Boot run configuration.

  1. In the main menu, go to Run | Edit Configurations or press Alt+Shift+F10.

  2. Select your Spring Boot run configuration or create a new one by clicking .

  3. Click Modify options and select Enable Scheduled Debugger.

Trigger scheduled methods

  1. Run your application by pressing Shift+F10 or clicking . Or start the debugger session by pressing Shift+F9 or clicking .

  2. In the gutter, next to a method annotated with @Scheduled, click . This will trigger the method regardless of the configured interval.

Trigger scheduled methods
Last modified: 14 August 2024