How not to override ThreadPoolTaskScheduler?

It seems that Flowable’s Spring Boot autoconfiguration will pick up and use any ThreadPoolTaskScheduler it finds in the Spring context. I have a ThreadPoolTaskScheduler bean that is needed for totally different purposes and I do not want Flowable to use that. Is it possible to prevent autoconfiguration from using my scheduler? Or do I just have to avoid exposing it to the Spring context?

That looks indeed like it: flowable-engine/ProcessEngineAutoConfiguration.java at main · flowable/flowable-engine · GitHub

As a alternative, you could expose your own SpringProcessEngineConfiguration, as it has @ConditionalOnMissingBean

To add to what @joram said. There is a slightly more complex logic for which executor we are going to use.

If you look at the code that Joram shared then you will see the following:

        AsyncListenableTaskExecutor asyncTaskExecutor = getIfAvailable(processTaskExecutor, taskExecutor);
        if (asyncTaskExecutor == null) {
            // Get the applicationTaskExecutor
            asyncTaskExecutor = applicationTaskExecutorProvider.getObject();
        }
        if (asyncTaskExecutor != null) {
            // The task executors are shared
            org.flowable.common.engine.api.async.AsyncTaskExecutor flowableTaskExecutor = new SpringAsyncTaskExecutor(asyncTaskExecutor);
            conf.setAsyncTaskExecutor(flowableTaskExecutor);
            conf.setAsyncHistoryTaskExecutor(flowableTaskExecutor);
        }

So the order of the priority of the AsyncListenableTaskExecutor that we are going to use is the following:

  1. AsyncListenableTaskExecutor qualified with @Process
  2. The unique AsyncListenableTaskExecutor in the application context
  3. AsyncListenableTaskExecutorqualified with the nameapplicationTaskExecutor` (i.e. the one auto configured by Spring Boot)

In your case if you are exposing ThreadPoolTaskScheduler then the 3rd option should kick in. However, looking in the Spring Boot TaskSchedulingAutoConfiguration and TaskExecutionAutoConfiguration both of them will back off if the bean you are exposing (the return type of your method) is ThreadPoolTaskScheduler, because that is an Executor as well.

If you want a custom TaskScheduler, I would suggest that you return TaskScheduler and not ThreadPoolTaskScheduler. In this way the default Spring applicationTaskExecutor` will kick in and Flowable will use that one.

1 Like

Ah, so simple… didn’t thought of that. Works like a charm, thanks!