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.
Press Ctrl+Alt+S to open settings and then select
.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.
To get a list of cron expression examples, press Ctrl+Space after the cron
keyword.
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.
In the main menu, go to
or press Alt+Shift+F10.Select your Spring Boot run configuration or create a new one by clicking .
Click Modify options and select Enable Scheduled Debugger.
Trigger scheduled methods
Run your application by pressing Shift+F10 or clicking . Or start the debugger session by pressing Shift+F9 or clicking .
In the gutter, next to a method annotated with
@Scheduled
, click . This will trigger the method regardless of the configured interval.