@@ -463,7 +463,7 @@ shown in this example:
463
463
<entry key="/remoting/AccountService" value-ref="accountExporter"/>
464
464
</util:map>
465
465
</property>
466
- <property name="port" value="8080" />
466
+ <property name="port" value="8080"/>
467
467
</bean>
468
468
----
469
469
@@ -2061,13 +2061,13 @@ containers that ships with Spring (in this case the `DefaultMessageListenerConta
2061
2061
[subs="verbatim,quotes"]
2062
2062
----
2063
2063
<!-- this is the Message Driven POJO (MDP) -->
2064
- <bean id="messageListener" class="jmsexample.ExampleListener" />
2064
+ <bean id="messageListener" class="jmsexample.ExampleListener"/>
2065
2065
2066
2066
<!-- and this is the message listener container -->
2067
2067
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
2068
2068
<property name="connectionFactory" ref="connectionFactory"/>
2069
2069
<property name="destination" ref="destination"/>
2070
- **<property name="messageListener" ref="messageListener" />**
2070
+ **<property name="messageListener" ref="messageListener"/>**
2071
2071
</bean>
2072
2072
----
2073
2073
@@ -2163,7 +2163,7 @@ POJO that we will make into an MDP via the following configuration.
2163
2163
<bean id="jmsContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
2164
2164
<property name="connectionFactory" ref="connectionFactory"/>
2165
2165
<property name="destination" ref="destination"/>
2166
- **<property name="messageListener" ref="messageListener" />**
2166
+ **<property name="messageListener" ref="messageListener"/>**
2167
2167
</bean>
2168
2168
----
2169
2169
@@ -5930,49 +5930,37 @@ behavior, it is possible to use this abstraction for your own needs.
5930
5930
==== TaskExecutor types
5931
5931
5932
5932
There are a number of pre-built implementations of `TaskExecutor` included with the
5933
- Spring distribution. In all likelihood, you shouldn't ever need to implement your own.
5933
+ Spring distribution. In all likelihood, you should never need to implement your own.
5934
+ The common out-of-the-box variants are:
5934
5935
5936
+ * `SyncTaskExecutor`
5937
+ This implementation does not execute invocations asynchronously. Instead, each
5938
+ invocation takes place in the calling thread. It is primarily used in situations
5939
+ where multi-threading is not necessary such as in simple test cases.
5935
5940
* `SimpleAsyncTaskExecutor`
5936
5941
This implementation does not reuse any threads, rather it starts up a new thread
5937
5942
for each invocation. However, it does support a concurrency limit which will block
5938
5943
any invocations that are over the limit until a slot has been freed up. If you
5939
- are looking for true pooling, see the discussions of `SimpleThreadPoolTaskExecutor`
5940
- and `ThreadPoolTaskExecutor` below.
5941
- * `SyncTaskExecutor`
5942
- This implementation doesn't execute invocations asynchronously. Instead, each
5943
- invocation takes place in the calling thread. It is primarily used in situations
5944
- where multi-threading isn't necessary such as simple test cases.
5944
+ are looking for true pooling, see `ThreadPoolTaskExecutor` below.
5945
5945
* `ConcurrentTaskExecutor`
5946
- This implementation is an adapter for a `java.util.concurrent.Executor` object .
5946
+ This implementation is an adapter for a `java.util.concurrent.Executor` instance .
5947
5947
There is an alternative, `ThreadPoolTaskExecutor`, that exposes the `Executor`
5948
- configuration parameters as bean properties. It is rare to need to use the
5949
- `ConcurrentTaskExecutor`, but if the `ThreadPoolTaskExecutor` isn't flexible
5950
- enough for your needs, the `ConcurrentTaskExecutor` is an alternative.
5951
- * `SimpleThreadPoolTaskExecutor`
5952
- This implementation is actually a subclass of Quartz's `SimpleThreadPool` which
5953
- listens to Spring's lifecycle callbacks. This is typically used when you have a
5954
- thread pool that may need to be shared by both Quartz and non-Quartz components.
5948
+ configuration parameters as bean properties. There is rarely a need to use
5949
+ `ConcurrentTaskExecutor` directly, but if the `ThreadPoolTaskExecutor` is not
5950
+ flexible enough for your needs, then `ConcurrentTaskExecutor` is an alternative.
5955
5951
* `ThreadPoolTaskExecutor`
5956
5952
This implementation is the most commonly used one. It exposes bean properties for
5957
5953
configuring a `java.util.concurrent.ThreadPoolExecutor` and wraps it in a `TaskExecutor`.
5958
5954
If you need to adapt to a different kind of `java.util.concurrent.Executor`, it is
5959
5955
recommended that you use a `ConcurrentTaskExecutor` instead.
5960
5956
* `WorkManagerTaskExecutor`
5961
-
5962
- +
5963
-
5964
- ****
5965
- CommonJ is a set of specifications jointly developed between BEA and IBM. These
5966
- specifications are not Java EE standards, but are standard across BEA's and IBM's
5967
- Application Server implementations.
5968
- ****
5969
-
5970
- +
5971
-
5972
- This implementation uses the CommonJ `WorkManager` as its backing implementation and is
5973
- the central convenience class for setting up a CommonJ `WorkManager` reference in a Spring
5974
- context. Similar to the `SimpleThreadPoolTaskExecutor`, this class implements the
5975
- `WorkManager` interface and therefore can be used directly as a `WorkManager` as well.
5957
+ This implementation uses a CommonJ `WorkManager` as its backing service provider
5958
+ and is the central convenience class for setting up CommonJ-based thread pool
5959
+ integration on WebLogic/WebSphere within a Spring application context.
5960
+ * `DefaultManagedTaskExecutor`
5961
+ This implementation uses a JNDI-obtained `ManagedExecutorService` in a JSR-236
5962
+ compatible runtime environment such as a Java EE 7+ application server,
5963
+ replacing a CommonJ WorkManager for that purpose.
5976
5964
5977
5965
5978
5966
[[scheduling-task-executor-usage]]
@@ -6000,7 +5988,6 @@ out a set of messages.
6000
5988
public void run() {
6001
5989
System.out.println(message);
6002
5990
}
6003
-
6004
5991
}
6005
5992
6006
5993
private TaskExecutor taskExecutor;
@@ -6014,7 +6001,6 @@ out a set of messages.
6014
6001
taskExecutor.execute(new MessagePrinterTask("Message" + i));
6015
6002
}
6016
6003
}
6017
-
6018
6004
}
6019
6005
----
6020
6006
@@ -6029,13 +6015,13 @@ been exposed.
6029
6015
[subs="verbatim,quotes"]
6030
6016
----
6031
6017
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
6032
- <property name="corePoolSize" value="5" />
6033
- <property name="maxPoolSize" value="10" />
6034
- <property name="queueCapacity" value="25" />
6018
+ <property name="corePoolSize" value="5"/>
6019
+ <property name="maxPoolSize" value="10"/>
6020
+ <property name="queueCapacity" value="25"/>
6035
6021
</bean>
6036
6022
6037
6023
<bean id="taskExecutorExample" class="TaskExecutorExample">
6038
- <constructor-arg ref="taskExecutor" />
6024
+ <constructor-arg ref="taskExecutor"/>
6039
6025
</bean>
6040
6026
----
6041
6027
@@ -6054,16 +6040,25 @@ with a variety of methods for scheduling tasks to run at some point in the futur
6054
6040
6055
6041
ScheduledFuture schedule(Runnable task, Trigger trigger);
6056
6042
6043
+ ScheduledFuture schedule(Runnable task, Instant startTime);
6044
+
6057
6045
ScheduledFuture schedule(Runnable task, Date startTime);
6058
6046
6047
+ ScheduledFuture scheduleAtFixedRate(Runnable task, Instant startTime, Duration period);
6048
+
6059
6049
ScheduledFuture scheduleAtFixedRate(Runnable task, Date startTime, long period);
6060
6050
6051
+ ScheduledFuture scheduleAtFixedRate(Runnable task, Duration period);
6052
+
6061
6053
ScheduledFuture scheduleAtFixedRate(Runnable task, long period);
6062
6054
6055
+ ScheduledFuture scheduleWithFixedDelay(Runnable task, Instant startTime, Duration delay);
6056
+
6063
6057
ScheduledFuture scheduleWithFixedDelay(Runnable task, Date startTime, long delay);
6064
6058
6065
- ScheduledFuture scheduleWithFixedDelay(Runnable task, long delay);
6059
+ ScheduledFuture scheduleWithFixedDelay(Runnable task, Duration delay);
6066
6060
6061
+ ScheduledFuture scheduleWithFixedDelay(Runnable task, long delay);
6067
6062
}
6068
6063
----
6069
6064
@@ -6077,8 +6072,8 @@ much more flexible.
6077
6072
[[scheduling-trigger-interface]]
6078
6073
==== Trigger interface
6079
6074
6080
- The `Trigger` interface is essentially inspired by JSR-236, which, as of Spring 3.0, has
6081
- not yet been officially implemented. The basic idea of the `Trigger` is that execution
6075
+ The `Trigger` interface is essentially inspired by JSR-236 which, as of Spring 3.0,
6076
+ was not yet officially implemented. The basic idea of the `Trigger` is that execution
6082
6077
times may be determined based on past execution outcomes or even arbitrary conditions.
6083
6078
If these determinations do take into account the outcome of the preceding execution,
6084
6079
that information is available within a `TriggerContext`. The `Trigger` interface itself
@@ -6090,7 +6085,6 @@ is quite simple:
6090
6085
public interface Trigger {
6091
6086
6092
6087
Date nextExecutionTime(TriggerContext triggerContext);
6093
-
6094
6088
}
6095
6089
----
6096
6090
@@ -6109,7 +6103,6 @@ default). Here you can see what methods are available for `Trigger` implementati
6109
6103
Date lastActualExecutionTime();
6110
6104
6111
6105
Date lastCompletionTime();
6112
-
6113
6106
}
6114
6107
----
6115
6108
@@ -6144,19 +6137,21 @@ could be configured externally and therefore easily modified or extended.
6144
6137
==== TaskScheduler implementations
6145
6138
6146
6139
As with Spring's `TaskExecutor` abstraction, the primary benefit of the `TaskScheduler`
6147
- is that code relying on scheduling behavior need not be coupled to a particular
6148
- scheduler implementation. The flexibility this provides is particularly relevant when
6149
- running within Application Server environments where threads should not be created
6150
- directly by the application itself. For such cases, Spring provides a
6151
- `TimerManagerTaskScheduler` that delegates to a CommonJ TimerManager instance, typically
6152
- configured with a JNDI-lookup.
6140
+ arrangement is that an application's scheduling needs are decoupled from the deployment
6141
+ environment. This abstraction level is particularly relevant when deploying to an
6142
+ application server environment where threads should not be created directly by the
6143
+ application itself. For such scenarios, Spring provides a `TimerManagerTaskScheduler`
6144
+ delegating to a CommonJ TimerManager on WebLogic/WebSphere as well as a more recent
6145
+ `DefaultManagedTaskScheduler` delegating to a JSR-236 `ManagedScheduledExecutorService`
6146
+ in a Java EE 7+ environment, both typically configured with a JNDI lookup.
6153
6147
6154
- A simpler alternative, the `ThreadPoolTaskScheduler`, can be used whenever external
6155
- thread management is not a requirement. Internally, it delegates to a
6156
- `ScheduledExecutorService` instance. `ThreadPoolTaskScheduler` actually implements
6157
- Spring's `TaskExecutor` interface as well, so that a single instance can be used for
6158
- asynchronous execution __as soon as possible__ as well as scheduled, and potentially
6159
- recurring, executions.
6148
+ Whenever external thread management is not a requirement, a simpler alternative is
6149
+ a local `ScheduledExecutorService` setup within the application which can be adapted
6150
+ through Spring's `ConcurrentTaskScheduler`. As a convenience, Spring also provides a
6151
+ `ThreadPoolTaskScheduler` which internally delegates to a `ScheduledExecutorService`,
6152
+ providing common bean-style configuration along the lines of `ThreadPoolTaskExecutor`.
6153
+ These variants work perfectly fine for locally embedded thread pool setups in lenient
6154
+ application server environments as well, in particular on Tomcat and Jetty.
6160
6155
6161
6156
6162
6157
@@ -7377,8 +7372,7 @@ Alternatively for XML configuration use the `cache:annotation-driven` element:
7377
7372
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
7378
7373
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
7379
7374
7380
- <cache:annotation-driven />
7381
-
7375
+ <cache:annotation-driven/>
7382
7376
</beans>
7383
7377
----
7384
7378
0 commit comments