Browse Source

Polish scheduling Javadoc

pull/27330/head
Sam Brannen 4 years ago
parent
commit
c27ec00ae9
  1. 30
      spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java
  2. 2
      spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java
  3. 15
      spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java
  4. 18
      spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java

30
spring-context/src/main/java/org/springframework/scheduling/annotation/EnableScheduling.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -31,7 +31,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/**
* Enables Spring's scheduled task execution capability, similar to
* functionality found in Spring's {@code <task:*>} XML namespace. To be used
* on @{@link Configuration} classes as follows:
* on {@link Configuration @Configuration} classes as follows:
*
* <pre class="code">
* &#064;Configuration
@ -41,8 +41,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -41,8 +41,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* // various &#064;Bean definitions
* }</pre>
*
* This enables detection of @{@link Scheduled} annotations on any Spring-managed
* bean in the container. For example, given a class {@code MyTask}
* <p>This enables detection of {@link Scheduled @Scheduled} annotations on any
* Spring-managed bean in the container. For example, given a class {@code MyTask}:
*
* <pre class="code">
* package com.myco.tasks;
@ -55,7 +55,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -55,7 +55,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* }
* }</pre>
*
* the following configuration would ensure that {@code MyTask.work()} is called
* <p>the following configuration would ensure that {@code MyTask.work()} is called
* once every 1000 ms:
*
* <pre class="code">
@ -69,7 +69,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -69,7 +69,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* }
* }</pre>
*
* Alternatively, if {@code MyTask} were annotated with {@code @Component}, the
* <p>Alternatively, if {@code MyTask} were annotated with {@code @Component}, the
* following configuration would ensure that its {@code @Scheduled} method is
* invoked at the desired interval:
*
@ -80,7 +80,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -80,7 +80,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* public class AppConfig {
* }</pre>
*
* Methods annotated with {@code @Scheduled} may even be declared directly within
* <p>Methods annotated with {@code @Scheduled} may even be declared directly within
* {@code @Configuration} classes:
*
* <pre class="code">
@ -94,7 +94,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -94,7 +94,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* }
* }</pre>
*
* <p>By default, will be searching for an associated scheduler definition: either
* <p>By default, Spring will search for an associated scheduler definition: either
* a unique {@link org.springframework.scheduling.TaskScheduler} bean in the context,
* or a {@code TaskScheduler} bean named "taskScheduler" otherwise; the same lookup
* will also be performed for a {@link java.util.concurrent.ScheduledExecutorService}
@ -141,11 +141,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -141,11 +141,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
* taskRegistrar.setScheduler(taskScheduler());
* taskRegistrar.addTriggerTask(
* new Runnable() {
* public void run() {
* myTask().work();
* }
* },
* () -&gt; myTask().work(),
* new CustomTrigger()
* );
* }
@ -165,7 +161,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -165,7 +161,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* configuration:
*
* <pre class="code">
* &lt;beans>
* &lt;beans&gt;
*
* &lt;task:annotation-driven scheduler="taskScheduler"/&gt;
*
@ -180,13 +176,13 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -180,13 +176,13 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* &lt;/beans&gt;
* </pre>
*
* The examples are equivalent save that in XML a <em>fixed-rate</em> period is used
* <p>The examples are equivalent save that in XML a <em>fixed-rate</em> period is used
* instead of a custom <em>{@code Trigger}</em> implementation; this is because the
* {@code task:} namespace {@code scheduled} cannot easily expose such support. This is
* but one demonstration how the code-based approach allows for maximum configurability
* through direct access to actual componentry.<p>
* through direct access to actual componentry.
*
* <b>Note: {@code @EnableScheduling} applies to its local application context only,
* <p><b>Note: {@code @EnableScheduling} applies to its local application context only,
* allowing for selective scheduling of beans at different levels.</b> Please redeclare
* {@code @EnableScheduling} in each individual context, e.g. the common root web
* application context and any separate {@code DispatcherServlet} application contexts,

2
spring-context/src/main/java/org/springframework/scheduling/annotation/Scheduled.java

@ -38,7 +38,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar; @@ -38,7 +38,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* <p>Processing of {@code @Scheduled} annotations is performed by
* registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be
* done manually or, more conveniently, through the {@code <task:annotation-driven/>}
* element or @{@link EnableScheduling} annotation.
* XML element or {@link EnableScheduling @EnableScheduling} annotation.
*
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
* <em>composed annotations</em> with attribute overrides.

15
spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java

@ -78,9 +78,10 @@ import org.springframework.util.StringUtils; @@ -78,9 +78,10 @@ import org.springframework.util.StringUtils;
import org.springframework.util.StringValueResolver;
/**
* Bean post-processor that registers methods annotated with @{@link Scheduled}
* to be invoked by a {@link org.springframework.scheduling.TaskScheduler} according
* to the "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
* Bean post-processor that registers methods annotated with
* {@link Scheduled @Scheduled} to be invoked by a
* {@link org.springframework.scheduling.TaskScheduler} according to the
* "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
*
* <p>This post-processor is automatically registered by Spring's
* {@code <task:annotation-driven>} XML element, and also by the
@ -88,8 +89,9 @@ import org.springframework.util.StringValueResolver; @@ -88,8 +89,9 @@ import org.springframework.util.StringValueResolver;
*
* <p>Autodetects any {@link SchedulingConfigurer} instances in the container,
* allowing for customization of the scheduler to be used or for fine-grained
* control over task registration (e.g. registration of {@link Trigger} tasks.
* See the @{@link EnableScheduling} javadocs for complete usage details.
* control over task registration (e.g. registration of {@link Trigger} tasks).
* See the {@link EnableScheduling @EnableScheduling} javadocs for complete usage
* details.
*
* @author Mark Fisher
* @author Juergen Hoeller
@ -153,7 +155,8 @@ public class ScheduledAnnotationBeanPostProcessor @@ -153,7 +155,8 @@ public class ScheduledAnnotationBeanPostProcessor
/**
* Create a {@code ScheduledAnnotationBeanPostProcessor} delegating to the
* specified {@link ScheduledTaskRegistrar}.
* @param registrar the ScheduledTaskRegistrar to register @Scheduled tasks on
* @param registrar the ScheduledTaskRegistrar to register {@code @Scheduled}
* tasks on
* @since 5.1
*/
public ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar) {

18
spring-context/src/main/java/org/springframework/scheduling/annotation/SchedulingConfigurer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,17 +19,17 @@ package org.springframework.scheduling.annotation; @@ -19,17 +19,17 @@ package org.springframework.scheduling.annotation;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/**
* Optional interface to be implemented by @{@link
* org.springframework.context.annotation.Configuration Configuration} classes annotated
* with @{@link EnableScheduling}. Typically used for setting a specific
* Optional interface to be implemented by {@link
* org.springframework.context.annotation.Configuration @Configuration} classes annotated
* with {@link EnableScheduling @EnableScheduling}. Typically used for setting a specific
* {@link org.springframework.scheduling.TaskScheduler TaskScheduler} bean to be used when
* executing scheduled tasks or for registering scheduled tasks in a <em>programmatic</em>
* fashion as opposed to the <em>declarative</em> approach of using the @{@link Scheduled}
* annotation. For example, this may be necessary when implementing {@link
* org.springframework.scheduling.Trigger Trigger}-based tasks, which are not supported by
* the {@code @Scheduled} annotation.
* fashion as opposed to the <em>declarative</em> approach of using the
* {@link Scheduled @Scheduled} annotation. For example, this may be necessary
* when implementing {@link org.springframework.scheduling.Trigger Trigger}-based
* tasks, which are not supported by the {@code @Scheduled} annotation.
*
* <p>See @{@link EnableScheduling} for detailed usage examples.
* <p>See {@link EnableScheduling @EnableScheduling} for detailed usage examples.
*
* @author Chris Beams
* @since 3.1

Loading…
Cancel
Save