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:
IntelliJ IDEA provides coding assistance and human-readable descriptions for cron expressions in scheduled Spring, Quarkus, and Micronaut services.
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.
note
The Cron Expressions plugin is not available in IntelliJ IDEA Community Edition.
Press CtrlAlt0S to open settings and then select Plugins.
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 CtrlSpace after the cron
keyword.
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.
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 Run | Edit Configurations or press AltShiftF10.
Select your Spring Boot run configuration or create a new one by clicking .
Click Modify options and select Enable Scheduled Debugger.
Run your application by pressing ShiftF10 or clicking . Or start the debugger session by pressing ShiftF9 or clicking .
In the gutter, next to a method annotated with
@Scheduled
, click . This will trigger the method regardless of the configured interval.
Thanks for your feedback!