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
Support TimeUnit
in the @Scheduled
annotation
#27309
Conversation
@Axzial Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@Axzial Thank you for signing the Contributor License Agreement! |
# Conflicts: # spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
# Conflicts: # spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
# Conflicts: # spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
...ain/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
Outdated
Show resolved
Hide resolved
TimeUnit
in the @Scheduled
annotation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've requested some minor changes.
Please also introduce some tests that use different TimeUnit
values.
If you can get these changes in soon, this can be included in Spring Framework 5.3.10.
spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
Outdated
Show resolved
Hide resolved
spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
Outdated
Show resolved
Hide resolved
...ain/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the requested changes!
I'll make a final review of this PR in time for 5.3.10.
@@ -407,7 +408,7 @@ protected void processScheduled(Scheduled scheduled, Method method, Object bean) | |||
} | |||
if (StringUtils.hasLength(initialDelayString)) { | |||
try { | |||
initialDelay = parseDelayAsLong(initialDelayString); | |||
initialDelay = TimeUnit.MILLISECONDS.convert(parseDelayAsLong(initialDelayString), scheduled.timeUnit()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While performing a final review, I noticed that this introduces a 🐛 when the String
is a java.time.Duration
string, since the value gets converted to milliseconds and then converted again using the configured time unit.
I've fixed this locally, and you can see the result once I've merged the changes into main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok, good to know ! Thank you.
@Axzial, if you would like for your name to be included in the |
Sure, Victor Brown, Thank you. |
This commit also fixes a bug introduced in commit e99b43b, where java.time.Duration strings were converted to milliseconds and then converted again using the configured TimeUnit. See spring-projectsgh-27309
This commit introduces a new `timeUnit` attribute in the @scheduled annotation to allow the user to specify a time unit other than milliseconds. Closes spring-projectsgh-27309
This commit also fixes a bug introduced in commit e99b43b, where java.time.Duration strings were converted to milliseconds and then converted again using the configured TimeUnit. See spring-projectsgh-27309
Added an option to use
java.util.concurrent.TimeUnit
withfixedDelay
,fixedRate
andinitialDelay
in the@Scheduled
annotation. Using by default milliseconds as before.