Java源码示例:io.micronaut.scheduling.annotation.Scheduled

示例1
@Override
protected List<AnnotationValue<?>> mapInternal(AnnotationValue<Annotation> annotation, VisitorContext visitorContext) {
    final AnnotationValueBuilder<?> builder = AnnotationValue.builder(Scheduled.class);
    annotation.get("cron", String.class).ifPresent(s -> builder.member("cron", s));

    // members that take numbers needed "ms" appending
    annotation.get("fixedDelay", String.class).ifPresent(s -> builder.member("fixedDelay", s + "ms"));
    annotation.get("fixedRate", String.class).ifPresent(s -> builder.member("fixedRate", s + "ms"));
    annotation.get("initialDelay", String.class).ifPresent(s -> builder.member("initialDelay", s + "ms"));

    annotation.get("fixedDelayString", String.class).ifPresent(s -> builder.member("fixedDelay", s));
    annotation.get("fixedRateString", String.class).ifPresent(s -> builder.member("fixedRate", s));
    annotation.get("initialDelayString", String.class).ifPresent(s -> builder.member("initialDelay", s));

    final AnnotationValue<?> scheduledAnn = builder
            .build();
    return Collections.singletonList(scheduledAnn);
}
 
示例2
/**
 * Send ka messages to active sessions.
 */
@Scheduled(fixedDelay =
        "${" + GraphQLConfiguration.PREFIX + "." + GraphQLWsConfiguration.KEEP_ALIVE_INTERVAL + ":"
                + GraphQLWsConfiguration.DEFAULT_KEEP_ALIVE_INTERVAL + "}")
public void keepAliveSender() {
    broadcaster.broadcastSync(kaMessage, state::isActive);
}
 
示例3
@Scheduled(fixedRate = "100ms")
@SchedulerLock(name = "reportCurrentTime")
public void reportCurrentTime() {
    assertLocked();
    called.set(true);
    System.out.println(new Date());
}
 
示例4
@Scheduled(fixedRate = "8h")
public void importBankStatement() {
   log.info("Starting bank statement import job");
   inPaymentRegistrationService.registerInPayments(jobCfg.getImportDir(), LocalDate.now());
   
}