Change tasks sample to parallel execution
- Now defining parallel region execution policy as TaskExecutor won't work anymore. - Relates #397
This commit is contained in:
@@ -86,11 +86,9 @@ include::samples/demo/tasks/Application.java[tags=snippetAD]
|
||||
----
|
||||
====
|
||||
|
||||
Currently, the default region execution is synchronous, but you can change
|
||||
it to be asynchronous by changing `TaskExecutor`. Task simulates
|
||||
work by sleeping two seconds so that you can see how actions in
|
||||
regions are executed inparallel.
|
||||
The following listing shows the `TaskExecutor` bean definition:
|
||||
Default region execution is synchronous meaning a regions would be processed
|
||||
sequentially. In this sample we simply want all task regions to get processed
|
||||
parallel. This can be accomplished by defining `RegionExecutionPolicy`:
|
||||
|
||||
====
|
||||
[source,java,indent=0]
|
||||
@@ -109,22 +107,24 @@ State machine started
|
||||
Entry state READY
|
||||
|
||||
sm>tasks run
|
||||
Exit state READY
|
||||
Entry state TASKS
|
||||
run task on T3
|
||||
run task on T2
|
||||
run task on T1
|
||||
run task on T3
|
||||
run task on T2 done
|
||||
run task on T1 done
|
||||
run task on T3 done
|
||||
Entry state T2
|
||||
Entry state T3
|
||||
Entry state T1
|
||||
Entry state T3
|
||||
Exit state T2
|
||||
Exit state T1
|
||||
Exit state T3
|
||||
Entry state T3E
|
||||
Entry state T1E
|
||||
Entry state T2E
|
||||
Entry state T3E
|
||||
Exit state TASKS
|
||||
Entry state JOIN
|
||||
Exit state JOIN
|
||||
Entry state READY
|
||||
----
|
||||
====
|
||||
|
||||
@@ -33,9 +33,11 @@ import org.springframework.statemachine.action.Action;
|
||||
import org.springframework.statemachine.annotation.OnTransition;
|
||||
import org.springframework.statemachine.config.EnableStateMachine;
|
||||
import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter;
|
||||
import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineStateConfigurer;
|
||||
import org.springframework.statemachine.config.builders.StateMachineTransitionConfigurer;
|
||||
import org.springframework.statemachine.guard.Guard;
|
||||
import org.springframework.statemachine.region.RegionExecutionPolicy;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -48,6 +50,16 @@ public class Application {
|
||||
static class StateMachineConfig
|
||||
extends EnumStateMachineConfigurerAdapter<States, Events> {
|
||||
|
||||
//tag::snippetAE[]
|
||||
@Override
|
||||
public void configure(StateMachineConfigurationConfigurer<States, Events> config)
|
||||
throws Exception {
|
||||
config
|
||||
.withConfiguration()
|
||||
.regionExecutionPolicy(RegionExecutionPolicy.PARALLEL);
|
||||
}
|
||||
//end::snippetAE[]
|
||||
|
||||
//tag::snippetAA[]
|
||||
@Override
|
||||
public void configure(StateMachineStateConfigurer<States, Events> states)
|
||||
@@ -195,16 +207,6 @@ public class Application {
|
||||
public Tasks tasks() {
|
||||
return new Tasks();
|
||||
}
|
||||
|
||||
//tag::snippetAE[]
|
||||
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
|
||||
public TaskExecutor taskExecutor() {
|
||||
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
|
||||
taskExecutor.setCorePoolSize(5);
|
||||
return taskExecutor;
|
||||
}
|
||||
//end::snippetAE[]
|
||||
|
||||
}
|
||||
|
||||
//tag::snippetB[]
|
||||
|
||||
Reference in New Issue
Block a user