Asynchronous execution of sub-states in parallel instances of spring state machineIs Inheritance in Struts2 Model-Driven Action possible?Persisting & Restoring Current State in Spring StatemachineSpring Security Thymleaf static resources don't loadParallel execution in spring state machineSpring Sub State Machine doesn't initiatespring state machine resetSpring State MachineDistributed state-machine's zookeeper ensemble fails while processing parallel regions with error KeeperErrorCode = BadVersionFork and Join: a problem with parallel execution of two regions in spring state machine
2019 gold coins to share
How to write sign "|" (or) in LaTeX?
Can there be absolute velocity?
A Salute to Poetry
bash vs. zsh: What are the practical differences?
How do you play "tenth" chords on the guitar?
How far would a landing Airbus A380 go until it stops with no brakes?
How to avoid typing 'git' at the begining of every Git command
Could a person damage a jet airliner - from the outside - with their bare hands?
Why is the output signal of my amplifier heavily distorted?
If there's something that implicates the president why is there then a national security issue? (John Dowd)
Can a human be transformed into a Mind Flayer?
Is Lambda Calculus purely syntactic?
Does putting salt first make it easier for attacker to bruteforce the hash?
Command of files and size
Confused with atmospheric pressure equals plastic balloon’s inner pressure
Flat with smooth fibers implies formally smooth?
How to befriend someone who doesn't like to talk?
Why is the length of the Kelvin unit of temperature equal to that of the Celsius unit?
Who is "He that flies" in Lord of the Rings?
C++ logging library
Is there a DSLR/mirorless camera with minimal options like a classic, simple SLR?
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
Trying to get (more) accurate readings from thermistor (electronics, math, and code inside)
Asynchronous execution of sub-states in parallel instances of spring state machine
Is Inheritance in Struts2 Model-Driven Action possible?Persisting & Restoring Current State in Spring StatemachineSpring Security Thymleaf static resources don't loadParallel execution in spring state machineSpring Sub State Machine doesn't initiatespring state machine resetSpring State MachineDistributed state-machine's zookeeper ensemble fails while processing parallel regions with error KeeperErrorCode = BadVersionFork and Join: a problem with parallel execution of two regions in spring state machine
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to create a few instances of state machine from one uml-model. I use stateMachineFactory. I would like these machines working independently and asynchrously.
Everything work great if I use only "base" states. Machine instances can independently go to stateB and StateC. However, when I use regions and sub-states (stateD), machine instances execute action (insideStateD1) one after another. Please look at
.
I've found that states are executed via stateMachineTaskExecutor (which default is SyncTaskExecutor) but substates are executed via taskScheduler (which default is ConcurrentTaskScheduler).
This is configuration:
@Configuration
@EnableStateMachineFactory
public class StateMachineConfig extends StateMachineConfigurerAdapter<String, String>
@Autowired
StateMachineComponentResolver<String, String> stateMachineComponentResolver;
@Bean
public StateMachineModelFactory<String, String> modelFactory()
UmlStateMachineModelFactory umlStateMachineModelFactory = new UmlStateMachineModelFactory("classpath:uml/testSM1.uml");
umlStateMachineModelFactory.setStateMachineComponentResolver(stateMachineComponentResolver);
return umlStateMachineModelFactory;
@Override
public void configure(StateMachineModelConfigurer<String, String> model) throws Exception
model
.withModel()
.factory(modelFactory());
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception
config
.withConfiguration()
// .taskExecutor() // I tried various taskExecutors
// .taskScheduler() // I tried various taskSchedulers
;
What is the correct way to achieve many instances of state machine from the same model?
java spring spring-statemachine
add a comment |
I am trying to create a few instances of state machine from one uml-model. I use stateMachineFactory. I would like these machines working independently and asynchrously.
Everything work great if I use only "base" states. Machine instances can independently go to stateB and StateC. However, when I use regions and sub-states (stateD), machine instances execute action (insideStateD1) one after another. Please look at
.
I've found that states are executed via stateMachineTaskExecutor (which default is SyncTaskExecutor) but substates are executed via taskScheduler (which default is ConcurrentTaskScheduler).
This is configuration:
@Configuration
@EnableStateMachineFactory
public class StateMachineConfig extends StateMachineConfigurerAdapter<String, String>
@Autowired
StateMachineComponentResolver<String, String> stateMachineComponentResolver;
@Bean
public StateMachineModelFactory<String, String> modelFactory()
UmlStateMachineModelFactory umlStateMachineModelFactory = new UmlStateMachineModelFactory("classpath:uml/testSM1.uml");
umlStateMachineModelFactory.setStateMachineComponentResolver(stateMachineComponentResolver);
return umlStateMachineModelFactory;
@Override
public void configure(StateMachineModelConfigurer<String, String> model) throws Exception
model
.withModel()
.factory(modelFactory());
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception
config
.withConfiguration()
// .taskExecutor() // I tried various taskExecutors
// .taskScheduler() // I tried various taskSchedulers
;
What is the correct way to achieve many instances of state machine from the same model?
java spring spring-statemachine
add a comment |
I am trying to create a few instances of state machine from one uml-model. I use stateMachineFactory. I would like these machines working independently and asynchrously.
Everything work great if I use only "base" states. Machine instances can independently go to stateB and StateC. However, when I use regions and sub-states (stateD), machine instances execute action (insideStateD1) one after another. Please look at
.
I've found that states are executed via stateMachineTaskExecutor (which default is SyncTaskExecutor) but substates are executed via taskScheduler (which default is ConcurrentTaskScheduler).
This is configuration:
@Configuration
@EnableStateMachineFactory
public class StateMachineConfig extends StateMachineConfigurerAdapter<String, String>
@Autowired
StateMachineComponentResolver<String, String> stateMachineComponentResolver;
@Bean
public StateMachineModelFactory<String, String> modelFactory()
UmlStateMachineModelFactory umlStateMachineModelFactory = new UmlStateMachineModelFactory("classpath:uml/testSM1.uml");
umlStateMachineModelFactory.setStateMachineComponentResolver(stateMachineComponentResolver);
return umlStateMachineModelFactory;
@Override
public void configure(StateMachineModelConfigurer<String, String> model) throws Exception
model
.withModel()
.factory(modelFactory());
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception
config
.withConfiguration()
// .taskExecutor() // I tried various taskExecutors
// .taskScheduler() // I tried various taskSchedulers
;
What is the correct way to achieve many instances of state machine from the same model?
java spring spring-statemachine
I am trying to create a few instances of state machine from one uml-model. I use stateMachineFactory. I would like these machines working independently and asynchrously.
Everything work great if I use only "base" states. Machine instances can independently go to stateB and StateC. However, when I use regions and sub-states (stateD), machine instances execute action (insideStateD1) one after another. Please look at
.
I've found that states are executed via stateMachineTaskExecutor (which default is SyncTaskExecutor) but substates are executed via taskScheduler (which default is ConcurrentTaskScheduler).
This is configuration:
@Configuration
@EnableStateMachineFactory
public class StateMachineConfig extends StateMachineConfigurerAdapter<String, String>
@Autowired
StateMachineComponentResolver<String, String> stateMachineComponentResolver;
@Bean
public StateMachineModelFactory<String, String> modelFactory()
UmlStateMachineModelFactory umlStateMachineModelFactory = new UmlStateMachineModelFactory("classpath:uml/testSM1.uml");
umlStateMachineModelFactory.setStateMachineComponentResolver(stateMachineComponentResolver);
return umlStateMachineModelFactory;
@Override
public void configure(StateMachineModelConfigurer<String, String> model) throws Exception
model
.withModel()
.factory(modelFactory());
@Override
public void configure(StateMachineConfigurationConfigurer<String, String> config) throws Exception
config
.withConfiguration()
// .taskExecutor() // I tried various taskExecutors
// .taskScheduler() // I tried various taskSchedulers
;
What is the correct way to achieve many instances of state machine from the same model?
java spring spring-statemachine
java spring spring-statemachine
edited Mar 24 at 21:44
Michal
1,0191222
1,0191222
asked Mar 24 at 21:08
Skaikru87Skaikru87
113
113
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Multiple instances of a SM can be obtained by the StateMachineFactory.
stateMachineFactory.getStateMachine(); //builds a new state machine
The configuration that you have created in StateMachineConfig applies to all SM instances.
Spring State Machine uses TaskExecutor for region executions (doesn't matter top level or nested regions) and by default it's synchronous. To achieve async execution you need to override the default task executor. This can be achieved in the configuration:
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception
config
.withConfiguration()
//other configs
.taskExecutor(myAsyncTaskExecutor())
public TaskExecutor myAsyncTaskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
or by declaring a bean:
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
TaskScheduler is used for action executions (actions associated with states or transitions) and not for sub-states.
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328601%2fasynchronous-execution-of-sub-states-in-parallel-instances-of-spring-state-machi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Multiple instances of a SM can be obtained by the StateMachineFactory.
stateMachineFactory.getStateMachine(); //builds a new state machine
The configuration that you have created in StateMachineConfig applies to all SM instances.
Spring State Machine uses TaskExecutor for region executions (doesn't matter top level or nested regions) and by default it's synchronous. To achieve async execution you need to override the default task executor. This can be achieved in the configuration:
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception
config
.withConfiguration()
//other configs
.taskExecutor(myAsyncTaskExecutor())
public TaskExecutor myAsyncTaskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
or by declaring a bean:
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
TaskScheduler is used for action executions (actions associated with states or transitions) and not for sub-states.
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
add a comment |
Multiple instances of a SM can be obtained by the StateMachineFactory.
stateMachineFactory.getStateMachine(); //builds a new state machine
The configuration that you have created in StateMachineConfig applies to all SM instances.
Spring State Machine uses TaskExecutor for region executions (doesn't matter top level or nested regions) and by default it's synchronous. To achieve async execution you need to override the default task executor. This can be achieved in the configuration:
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception
config
.withConfiguration()
//other configs
.taskExecutor(myAsyncTaskExecutor())
public TaskExecutor myAsyncTaskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
or by declaring a bean:
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
TaskScheduler is used for action executions (actions associated with states or transitions) and not for sub-states.
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
add a comment |
Multiple instances of a SM can be obtained by the StateMachineFactory.
stateMachineFactory.getStateMachine(); //builds a new state machine
The configuration that you have created in StateMachineConfig applies to all SM instances.
Spring State Machine uses TaskExecutor for region executions (doesn't matter top level or nested regions) and by default it's synchronous. To achieve async execution you need to override the default task executor. This can be achieved in the configuration:
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception
config
.withConfiguration()
//other configs
.taskExecutor(myAsyncTaskExecutor())
public TaskExecutor myAsyncTaskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
or by declaring a bean:
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
TaskScheduler is used for action executions (actions associated with states or transitions) and not for sub-states.
Multiple instances of a SM can be obtained by the StateMachineFactory.
stateMachineFactory.getStateMachine(); //builds a new state machine
The configuration that you have created in StateMachineConfig applies to all SM instances.
Spring State Machine uses TaskExecutor for region executions (doesn't matter top level or nested regions) and by default it's synchronous. To achieve async execution you need to override the default task executor. This can be achieved in the configuration:
@Override
public void configure(StateMachineConfigurationConfigurer<States, Events> config) throws Exception
config
.withConfiguration()
//other configs
.taskExecutor(myAsyncTaskExecutor())
public TaskExecutor myAsyncTaskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
or by declaring a bean:
@Bean(name = StateMachineSystemConstants.TASK_EXECUTOR_BEAN_NAME)
public TaskExecutor taskExecutor()
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
return taskExecutor;
TaskScheduler is used for action executions (actions associated with states or transitions) and not for sub-states.
answered Mar 25 at 16:55
hovanessyanhovanessyan
25k64465
25k64465
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
add a comment |
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Thanks for your response. Your answer inspired me to check a few things. I created two classes implementing interface Action and added its to state machine by StateMachineComponentResolver: action associated with transition fire StateA->StateB) and action associated with stateC (function behaviour: insideStateC). I've found that TaskExecutor is used for actions associated with transitions and guards but TaskScheduler is used for action executions associated with states. Am I right? I had to override TaskScheduler (changed on ThreadPoolTaskScheduler).
– Skaikru87
Mar 26 at 11:24
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
Yes, if you want your actions to be executed in async manner, you have to override the default taskScheduer with one spawning multiple threads.
– hovanessyan
Mar 26 at 11:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55328601%2fasynchronous-execution-of-sub-states-in-parallel-instances-of-spring-state-machi%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown