Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring boot 3.2.2 @Scheduled with cron expression executing immediately after application startup. #32309

Closed
Kryptonian-C opened this issue Feb 22, 2024 · 1 comment
Labels
status: invalid An issue that we don't feel is valid

Comments

@Kryptonian-C
Copy link

I have an application currently running on Springboot 3.1.2. The app having @scheduled method with cron expression.

As soon as I update the spring-boot version to 3.2.2 the first execution happens immediately after the application startup.

If I switch back to 3.1.2 this doesn't happen and the scheduled job executes only at the time defined in CRON.

Is there something that we have to take care during the upgrade.

##Method :

@scheduled(cron = "${cron.expression.maximize-value}", zone = "${cron.timezone}")
public Flux maximizeValue() {...}

The class is annotated with @service.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 22, 2024
@bclozel bclozel transferred this issue from spring-projects/spring-boot Feb 22, 2024
@bclozel
Copy link
Member

bclozel commented Feb 22, 2024

Before Spring Framework 6.1, @Scheduled methods returning a Publisher type were not supported. In your case, the method itself was executed but the returned publisher was never subscribed to.

As of #29924 this is now supported. This means that such methods are executed right away to get the publisher and then schedule its subscription when the cron is due. Maybe your scheduled method has a log statement in it? In any case, a method returning a Publisher should be lazy and should not have side effects before subscription happens.

See the reference documentation for more on that.

I'm closing this issue as it works as expected.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants