@ -17,6 +17,7 @@
@@ -17,6 +17,7 @@
package org.springframework.scheduling.annotation ;
import java.lang.reflect.Method ;
import java.time.Duration ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collections ;
@ -362,9 +363,9 @@ public class ScheduledAnnotationBeanPostProcessor
@@ -362,9 +363,9 @@ public class ScheduledAnnotationBeanPostProcessor
}
if ( StringUtils . hasLength ( initialDelayString ) ) {
try {
initialDelay = Long . parse Long( initialDelayString ) ;
initialDelay = parseDelayAs Long( initialDelayString ) ;
}
catch ( NumberFormat Exception ex ) {
catch ( Runtime Exception ex ) {
throw new IllegalArgumentException (
"Invalid initialDelayString value \"" + initialDelayString + "\" - cannot parse into long" ) ;
}
@ -414,9 +415,9 @@ public class ScheduledAnnotationBeanPostProcessor
@@ -414,9 +415,9 @@ public class ScheduledAnnotationBeanPostProcessor
Assert . isTrue ( ! processedSchedule , errorMessage ) ;
processedSchedule = true ;
try {
fixedDelay = Long . parse Long( fixedDelayString ) ;
fixedDelay = parseDelayAs Long( fixedDelayString ) ;
}
catch ( NumberFormat Exception ex ) {
catch ( Runtime Exception ex ) {
throw new IllegalArgumentException (
"Invalid fixedDelayString value \"" + fixedDelayString + "\" - cannot parse into long" ) ;
}
@ -440,9 +441,9 @@ public class ScheduledAnnotationBeanPostProcessor
@@ -440,9 +441,9 @@ public class ScheduledAnnotationBeanPostProcessor
Assert . isTrue ( ! processedSchedule , errorMessage ) ;
processedSchedule = true ;
try {
fixedRate = Long . parse Long( fixedRateString ) ;
fixedRate = parseDelayAs Long( fixedRateString ) ;
}
catch ( NumberFormat Exception ex ) {
catch ( Runtime Exception ex ) {
throw new IllegalArgumentException (
"Invalid fixedRateString value \"" + fixedRateString + "\" - cannot parse into long" ) ;
}
@ -469,6 +470,17 @@ public class ScheduledAnnotationBeanPostProcessor
@@ -469,6 +470,17 @@ public class ScheduledAnnotationBeanPostProcessor
}
}
private static long parseDelayAsLong ( String value ) throws RuntimeException {
if ( value . length ( ) > 1 & & ( isP ( value . charAt ( 0 ) ) | | isP ( value . charAt ( 1 ) ) ) ) {
return Duration . parse ( value ) . toMillis ( ) ;
}
return Long . parseLong ( value ) ;
}
private static boolean isP ( char ch ) {
return ( ch = = 'P' | | ch = = 'p' ) ;
}
/ * *
* Return all currently scheduled tasks , from { @link Scheduled } methods