【问题标题】:Get fixedDelay value inside @Scheduled在@Scheduled 中获取fixedDelay 值
【发布时间】:2015-07-06 18:32:36
【问题描述】:
是否可以在正在执行的方法中获取fixedDelay 的值?
这样的事情是否存在:
@Scheduled(fixedDelay = 86400000) //one day
public void sendEmails() {
System.out.println(TaskExecutor.getCurrentFixedDelay()); // (would print 86400000)
}
【问题讨论】:
标签:
java
spring
scheduled-tasks
【解决方案1】:
public class AnnotationParameter {
@Scheduled(fixedDelay = 86400000) //one day
public void sendEmails() throws NoSuchMethodException
{
Method method = AnnotationParameter.class.getDeclaredMethod
("sendEmails");
Scheduled annotation = method.getAnnotation(Scheduled.class);
long fixedDelay = annotation.fixedDelay();
System.out.println(fixedDelay); // (would print 86400000)
}
public static void main(String[] args) throws NoSuchMethodException
{
new AnnotationParameter().sendEmails();
}
}