Skip to content

Commit 659500b

Browse files
committed
Polishing
1 parent 4235a11 commit 659500b

File tree

5 files changed

+85
-63
lines changed

5 files changed

+85
-63
lines changed

framework-docs/modules/ROOT/pages/integration/scheduling.adoc

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ The Spring Framework provides abstractions for the asynchronous execution and sc
55
tasks with the `TaskExecutor` and `TaskScheduler` interfaces, respectively. Spring also
66
features implementations of those interfaces that support thread pools or delegation to
77
CommonJ within an application server environment. Ultimately, the use of these
8-
implementations behind the common interfaces abstracts away the differences between Java
9-
SE 5, Java SE 6, and Jakarta EE environments.
8+
implementations behind the common interfaces abstracts away the differences between
9+
Java SE and Jakarta EE environments.
1010

11-
Spring also features integration classes to support scheduling with the `Timer`
12-
(part of the JDK since 1.3) and the https://www.quartz-scheduler.org/[Quartz Scheduler].
13-
You can set up both of those schedulers by using a `FactoryBean` with optional references to
14-
`Timer` or `Trigger` instances, respectively. Furthermore, a convenience class for both
15-
the Quartz Scheduler and the `Timer` is available that lets you invoke a method of
16-
an existing target object (analogous to the normal `MethodInvokingFactoryBean`
17-
operation).
11+
Spring also features integration classes to support scheduling with the
12+
https://www.quartz-scheduler.org/[Quartz Scheduler].
1813

1914

2015

@@ -261,8 +256,8 @@ execution.
261256
[[scheduling-enable-annotation-support]]
262257
=== Enable Scheduling Annotations
263258

264-
To enable support for `@Scheduled` and `@Async` annotations, you can add `@EnableScheduling` and
265-
`@EnableAsync` to one of your `@Configuration` classes, as the following example shows:
259+
To enable support for `@Scheduled` and `@Async` annotations, you can add `@EnableScheduling`
260+
and `@EnableAsync` to one of your `@Configuration` classes, as the following example shows:
266261

267262
[source,java,indent=0,subs="verbatim,quotes"]
268263
----
@@ -336,7 +331,7 @@ For example, the previous example can also be written as follows.
336331

337332
If you need a fixed-rate execution, you can use the `fixedRate` attribute within the
338333
annotation. The following method is invoked every five seconds (measured between the
339-
successive start times of each invocation).
334+
successive start times of each invocation):
340335

341336
[source,java,indent=0,subs="verbatim,quotes"]
342337
----
@@ -346,9 +341,9 @@ successive start times of each invocation).
346341
}
347342
----
348343

349-
For fixed-delay and fixed-rate tasks, you can specify an initial delay by indicating the
350-
amount of time to wait before the first execution of the method, as the following
351-
`fixedRate` example shows.
344+
For fixed-delay and fixed-rate tasks, you can specify an initial delay by indicating
345+
the amount of time to wait before the first execution of the method, as the following
346+
`fixedRate` example shows:
352347

353348
[source,java,indent=0,subs="verbatim,quotes"]
354349
----
@@ -417,8 +412,8 @@ to a method that returns `void`, as the following example shows:
417412

418413
Unlike the methods annotated with the `@Scheduled` annotation, these methods can expect
419414
arguments, because they are invoked in the "`normal`" way by callers at runtime rather
420-
than from a scheduled task being managed by the container. For example, the following code is
421-
a legitimate application of the `@Async` annotation:
415+
than from a scheduled task being managed by the container. For example, the following
416+
code is a legitimate application of the `@Async` annotation:
422417

423418
[source,java,indent=0,subs="verbatim,quotes"]
424419
----
@@ -442,15 +437,15 @@ that returns a value:
442437
}
443438
----
444439

445-
TIP: `@Async` methods may not only declare a regular `java.util.concurrent.Future` return type
446-
but also Spring's `org.springframework.util.concurrent.ListenableFuture` or, as of Spring
447-
4.2, JDK 8's `java.util.concurrent.CompletableFuture`, for richer interaction with the
448-
asynchronous task and for immediate composition with further processing steps.
440+
TIP: `@Async` methods may not only declare a regular `java.util.concurrent.Future` return
441+
type but also Spring's `org.springframework.util.concurrent.ListenableFuture` or, as of
442+
Spring 4.2, JDK 8's `java.util.concurrent.CompletableFuture`, for richer interaction with
443+
the asynchronous task and for immediate composition with further processing steps.
449444

450-
You can not use `@Async` in conjunction with lifecycle callbacks such as
451-
`@PostConstruct`. To asynchronously initialize Spring beans, you currently have to use
452-
a separate initializing Spring bean that then invokes the `@Async` annotated method on the
453-
target, as the following example shows:
445+
You can not use `@Async` in conjunction with lifecycle callbacks such as `@PostConstruct`.
446+
To asynchronously initialize Spring beans, you currently have to use a separate
447+
initializing Spring bean that then invokes the `@Async` annotated method on the target,
448+
as the following example shows:
454449

455450
[source,java,indent=0,subs="verbatim,quotes"]
456451
----
@@ -504,8 +499,8 @@ used when executing a given method. The following example shows how to do so:
504499
----
505500

506501
In this case, `"otherExecutor"` can be the name of any `Executor` bean in the Spring
507-
container, or it may be the name of a qualifier associated with any `Executor` (for example, as
508-
specified with the `<qualifier>` element or Spring's `@Qualifier` annotation).
502+
container, or it may be the name of a qualifier associated with any `Executor` (for example,
503+
as specified with the `<qualifier>` element or Spring's `@Qualifier` annotation).
509504

510505

511506
[[scheduling-annotation-support-exception]]
@@ -673,14 +668,15 @@ invoked on that object. The following listing shows a simple example:
673668
----
674669

675670
The scheduler is referenced by the outer element, and each individual
676-
task includes the configuration of its trigger metadata. In the preceding example, that
677-
metadata defines a periodic trigger with a fixed delay indicating the number of
671+
task includes the configuration of its trigger metadata. In the preceding example,
672+
that metadata defines a periodic trigger with a fixed delay indicating the number of
678673
milliseconds to wait after each task execution has completed. Another option is
679674
`fixed-rate`, indicating how often the method should be run regardless of how long
680-
any previous execution takes. Additionally, for both `fixed-delay` and `fixed-rate` tasks, you can specify an
681-
'initial-delay' parameter, indicating the number of milliseconds to wait
682-
before the first execution of the method. For more control, you can instead provide a `cron` attribute
683-
to provide a xref:integration/scheduling.adoc#scheduling-cron-expression[cron expression].
675+
any previous execution takes. Additionally, for both `fixed-delay` and `fixed-rate`
676+
tasks, you can specify an 'initial-delay' parameter, indicating the number of
677+
milliseconds to wait before the first execution of the method. For more control,
678+
you can instead provide a `cron` attribute to provide a
679+
xref:integration/scheduling.adoc#scheduling-cron-expression[cron expression].
684680
The following example shows these other options:
685681

686682
[source,xml,indent=0]
@@ -703,9 +699,8 @@ The following example shows these other options:
703699
All Spring cron expressions have to conform to the same format, whether you are using them in
704700
xref:integration/scheduling.adoc#scheduling-annotation-support-scheduled[`@Scheduled` annotations],
705701
xref:integration/scheduling.adoc#scheduling-task-namespace-scheduled-tasks[`task:scheduled-tasks` elements],
706-
or someplace else.
707-
A well-formed cron expression, such as `* * * * * *`, consists of six space-separated time and date
708-
fields, each with its own range of valid values:
702+
or someplace else. A well-formed cron expression, such as `* * * * * *`, consists of six
703+
space-separated time and date fields, each with its own range of valid values:
709704

710705

711706
....
@@ -770,9 +765,10 @@ Here are some examples:
770765
[[macros]]
771766
=== Macros
772767

773-
Expressions such as `0 0 * * * *` are hard for humans to parse and are, therefore, hard to fix in case of bugs.
774-
To improve readability, Spring supports the following macros, which represent commonly used sequences.
775-
You can use these macros instead of the six-digit value, thus: `@Scheduled(cron = "@hourly")`.
768+
Expressions such as `0 0 * * * *` are hard for humans to parse and are, therefore,
769+
hard to fix in case of bugs. To improve readability, Spring supports the following
770+
macros, which represent commonly used sequences. You can use these macros instead
771+
of the six-digit value, thus: `@Scheduled(cron = "@hourly")`.
776772

777773
|===
778774
|Macro | Meaning
@@ -789,18 +785,18 @@ You can use these macros instead of the six-digit value, thus: `@Scheduled(cron
789785
[[scheduling-quartz]]
790786
== Using the Quartz Scheduler
791787

792-
Quartz uses `Trigger`, `Job`, and `JobDetail` objects to realize scheduling of all kinds
793-
of jobs. For the basic concepts behind Quartz, see the
788+
Quartz uses `Trigger`, `Job`, and `JobDetail` objects to realize scheduling of all
789+
kinds of jobs. For the basic concepts behind Quartz, see the
794790
https://www.quartz-scheduler.org/[Quartz Web site]. For convenience purposes, Spring
795791
offers a couple of classes that simplify using Quartz within Spring-based applications.
796792

797793

798794
[[scheduling-quartz-jobdetail]]
799795
=== Using the `JobDetailFactoryBean`
800796

801-
Quartz `JobDetail` objects contain all the information needed to run a job. Spring provides a
802-
`JobDetailFactoryBean`, which provides bean-style properties for XML configuration purposes.
803-
Consider the following example:
797+
Quartz `JobDetail` objects contain all the information needed to run a job. Spring
798+
provides a `JobDetailFactoryBean`, which provides bean-style properties for XML
799+
configuration purposes. Consider the following example:
804800

805801
[source,xml,indent=0,subs="verbatim,quotes"]
806802
----
@@ -817,9 +813,9 @@ Consider the following example:
817813
The job detail configuration has all the information it needs to run the job (`ExampleJob`).
818814
The timeout is specified in the job data map. The job data map is available through the
819815
`JobExecutionContext` (passed to you at execution time), but the `JobDetail` also gets
820-
its properties from the job data mapped to properties of the job instance. So, in the following example,
821-
the `ExampleJob` contains a bean property named `timeout`, and the `JobDetail`
822-
has it applied automatically:
816+
its properties from the job data mapped to properties of the job instance. So, in the
817+
following example, the `ExampleJob` contains a bean property named `timeout`, and the
818+
`JobDetail` has it applied automatically:
823819

824820
[source,java,indent=0,subs="verbatim,quotes",chomp="-packages"]
825821
----
@@ -912,8 +908,8 @@ NOTE: By default, jobs will run in a concurrent fashion.
912908
[[scheduling-quartz-cron]]
913909
=== Wiring up Jobs by Using Triggers and `SchedulerFactoryBean`
914910

915-
We have created job details and jobs. We have also reviewed the convenience bean that lets
916-
you invoke a method on a specific object. Of course, we still need to schedule the
911+
We have created job details and jobs. We have also reviewed the convenience bean that
912+
lets you invoke a method on a specific object. Of course, we still need to schedule the
917913
jobs themselves. This is done by using triggers and a `SchedulerFactoryBean`. Several
918914
triggers are available within Quartz, and Spring offers two Quartz `FactoryBean`
919915
implementations with convenient defaults: `CronTriggerFactoryBean` and
@@ -944,9 +940,9 @@ The following listing uses both a `SimpleTriggerFactoryBean` and a `CronTriggerF
944940
</bean>
945941
----
946942

947-
The preceding example sets up two triggers, one running every 50 seconds with a starting delay of 10
948-
seconds and one running every morning at 6 AM. To finalize everything, we need to set up the
949-
`SchedulerFactoryBean`, as the following example shows:
943+
The preceding example sets up two triggers, one running every 50 seconds with a starting
944+
delay of 10 seconds and one running every morning at 6 AM. To finalize everything,
945+
we need to set up the `SchedulerFactoryBean`, as the following example shows:
950946

951947
[source,xml,indent=0,subs="verbatim,quotes"]
952948
----

spring-context/src/main/java/org/springframework/scheduling/config/FixedRateTask.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,4 @@ public FixedRateTask(Runnable runnable, Duration interval, Duration initialDelay
5656
super(task);
5757
}
5858

59-
6059
}

spring-context/src/main/java/org/springframework/scheduling/config/IntervalTask.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@ public IntervalTask(Runnable runnable, Duration interval, Duration initialDelay)
9999
}
100100

101101

102-
103-
104102
/**
105103
* Return how often in milliseconds the task should be executed.
106104
* @deprecated as of 6.0, in favor of {@link #getIntervalDuration()}

0 commit comments

Comments
 (0)