spring-projects / spring-statemachine

Spring Statemachine is a framework for application developers to use state machine concepts with Spring.
1.55k stars 609 forks source link

Build a StateMachine will build a threadPool? #841

Open zmjzmjzmj8 opened 4 years ago

zmjzmjzmj8 commented 4 years ago

A request will build a StateMachine
When I request many times, many thread pools are created.

That my code

StateMachineBuilder.Builder<S, E> seBuilder = StateMachineBuilder.builder(); seBuilder.configureConfiguration().withConfiguration().machineId(System.currentTimeMillis() + "") .listener(listener()) .beanFactory(beanFactory); configure(seBuilder.configureStates()); configure(seBuilder.configureTransitions()); StateMachine<S, E> stateMachine = seBuilder.build();

bigblue311 commented 4 years ago

We using StateMachineBuilder to build StateMachine for every each request. After running for a while, we found that the stateMachine created lots of threadPool without recycled but stay in waiting state.

Could you please help and give practices?thanks

threadPool
zassyne commented 4 years ago

You could provide your own taskExecutor & taskScheduler like:


config.withConfiguration()
                .taskExecutor(ThreadPoolTaskExecutor().also {
                    it.initialize()
                }).taskScheduler(ConcurrentTaskScheduler(Executors.newScheduledThreadPool(size)))