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 @@
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
/** /**
* Enables Spring's scheduled task execution capability, similar to * Enables Spring's scheduled task execution capability, similar to
* functionality found in Spring's {@code <task:*>} XML namespace. To be used * 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"> * <pre class="code">
* &#064;Configuration * &#064;Configuration
@ -41,8 +41,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* // various &#064;Bean definitions * // various &#064;Bean definitions
* }</pre> * }</pre>
* *
* This enables detection of @{@link Scheduled} annotations on any Spring-managed * <p>This enables detection of {@link Scheduled @Scheduled} annotations on any
* bean in the container. For example, given a class {@code MyTask} * Spring-managed bean in the container. For example, given a class {@code MyTask}:
* *
* <pre class="code"> * <pre class="code">
* package com.myco.tasks; * package com.myco.tasks;
@ -55,7 +55,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* } * }
* }</pre> * }</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: * once every 1000 ms:
* *
* <pre class="code"> * <pre class="code">
@ -69,7 +69,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* } * }
* }</pre> * }</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 * following configuration would ensure that its {@code @Scheduled} method is
* invoked at the desired interval: * invoked at the desired interval:
* *
@ -80,7 +80,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* public class AppConfig { * public class AppConfig {
* }</pre> * }</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: * {@code @Configuration} classes:
* *
* <pre class="code"> * <pre class="code">
@ -94,7 +94,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* } * }
* }</pre> * }</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, * a unique {@link org.springframework.scheduling.TaskScheduler} bean in the context,
* or a {@code TaskScheduler} bean named "taskScheduler" otherwise; the same lookup * or a {@code TaskScheduler} bean named "taskScheduler" otherwise; the same lookup
* will also be performed for a {@link java.util.concurrent.ScheduledExecutorService} * will also be performed for a {@link java.util.concurrent.ScheduledExecutorService}
@ -141,11 +141,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { * public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
* taskRegistrar.setScheduler(taskScheduler()); * taskRegistrar.setScheduler(taskScheduler());
* taskRegistrar.addTriggerTask( * taskRegistrar.addTriggerTask(
* new Runnable() { * () -&gt; myTask().work(),
* public void run() {
* myTask().work();
* }
* },
* new CustomTrigger() * new CustomTrigger()
* ); * );
* } * }
@ -165,7 +161,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* configuration: * configuration:
* *
* <pre class="code"> * <pre class="code">
* &lt;beans> * &lt;beans&gt;
* *
* &lt;task:annotation-driven scheduler="taskScheduler"/&gt; * &lt;task:annotation-driven scheduler="taskScheduler"/&gt;
* *
@ -180,13 +176,13 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
* &lt;/beans&gt; * &lt;/beans&gt;
* </pre> * </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 * 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 * {@code task:} namespace {@code scheduled} cannot easily expose such support. This is
* but one demonstration how the code-based approach allows for maximum configurability * 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 * allowing for selective scheduling of beans at different levels.</b> Please redeclare
* {@code @EnableScheduling} in each individual context, e.g. the common root web * {@code @EnableScheduling} in each individual context, e.g. the common root web
* application context and any separate {@code DispatcherServlet} application contexts, * 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;
* <p>Processing of {@code @Scheduled} annotations is performed by * <p>Processing of {@code @Scheduled} annotations is performed by
* registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be * registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be
* done manually or, more conveniently, through the {@code <task:annotation-driven/>} * 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 * <p>This annotation may be used as a <em>meta-annotation</em> to create custom
* <em>composed annotations</em> with attribute overrides. * <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;
import org.springframework.util.StringValueResolver; import org.springframework.util.StringValueResolver;
/** /**
* Bean post-processor that registers methods annotated with @{@link Scheduled} * Bean post-processor that registers methods annotated with
* to be invoked by a {@link org.springframework.scheduling.TaskScheduler} according * {@link Scheduled @Scheduled} to be invoked by a
* to the "fixedRate", "fixedDelay", or "cron" expression provided via the annotation. * {@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 * <p>This post-processor is automatically registered by Spring's
* {@code <task:annotation-driven>} XML element, and also by the * {@code <task:annotation-driven>} XML element, and also by the
@ -88,8 +89,9 @@ import org.springframework.util.StringValueResolver;
* *
* <p>Autodetects any {@link SchedulingConfigurer} instances in the container, * <p>Autodetects any {@link SchedulingConfigurer} instances in the container,
* allowing for customization of the scheduler to be used or for fine-grained * allowing for customization of the scheduler to be used or for fine-grained
* control over task registration (e.g. registration of {@link Trigger} tasks. * control over task registration (e.g. registration of {@link Trigger} tasks).
* See the @{@link EnableScheduling} javadocs for complete usage details. * See the {@link EnableScheduling @EnableScheduling} javadocs for complete usage
* details.
* *
* @author Mark Fisher * @author Mark Fisher
* @author Juergen Hoeller * @author Juergen Hoeller
@ -153,7 +155,8 @@ public class ScheduledAnnotationBeanPostProcessor
/** /**
* Create a {@code ScheduledAnnotationBeanPostProcessor} delegating to the * Create a {@code ScheduledAnnotationBeanPostProcessor} delegating to the
* specified {@link ScheduledTaskRegistrar}. * 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 * @since 5.1
*/ */
public ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar) { public ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar) {

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

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

Loading…
Cancel
Save