2024年3月31日发(作者:)

@Override

public Object postProcessAfterInitialization(Object bean, String beanName) {

if (bean instanceof AopInfrastructureBean || bean instanceof TaskScheduler ||

bean instanceof ScheduledExecutorService) {

// Ignore AOP infrastructure such as scoped proxies.

return bean;

}

Class targetClass = teTargetClass(bean);

if (!ns(targetClass) &&

idateClass(targetClass, (, ))) {

Map> annotatedMethods = Methods(targetClass,

(taLookup>) method -> {

Set scheduledMethods = gedRepeatableAnnotations(

method, , );

return (!y() ? scheduledMethods : null);

});

if (y()) {

(targetClass);

if (eEnabled()) {

("No @Scheduled annotations found on bean class: " + targetClass);

}

}

else {

// Non-empty set of methods

h((method, scheduledMethods) ->

h(scheduled -> processScheduled(scheduled, method, bean)));

if (eEnabled()) {

(() + " @Scheduled methods processed on bean '" + beanName +

"': " + annotatedMethods);

}

}

}

return bean;

}

ledAnnotationBeanPostProcessor#processScheduled

/**

* Process the given {@code @Scheduled} method declaration on the given bean.

* @param scheduled the @Scheduled annotation

* @param method the method that the annotation has been declared on

* @param bean the target bean instance

* @see #createRunnable(Object, Method)

*/

protected void processScheduled(Scheduled scheduled, Method method, Object bean) {

try {

Runnable runnable = createRunnable(bean, method);

boolean processedSchedule = false;

String errorMessage =

"Exactly one of the 'cron', 'fixedDelay(String)', or 'fixedRate(String)' attributes is required";

Set tasks = new LinkedHashSet<>(4);

// Determine initial delay

long initialDelay = lDelay();

String initialDelayString = lDelayString();

if (t(initialDelayString)) {

(initialDelay < 0, "Specify 'initialDelay' or 'initialDelayString', not both");

if (edValueResolver != null) {

initialDelayString = eStringValue(initialDelayString);

}

if (gth(initialDelayString)) {

try {

initialDelay = parseDelayAsLong(initialDelayString);

}

catch (RuntimeException ex) {