# Gracefully Switching Off Background Threads

**URL:** <https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369>\
**Category:** Flowable Engine\
**Created:** [February 4, 2020, 9:54am UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369 "2020-02-04T09:54:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [February 4, 2020, 9:54am UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/1 "2020-02-04T09:54:12Z")

</div>

Dear Flowable experts,

Is there a functionality in the Engine to gracefully pause all the background threads and switch them (all) back on if needed?

The reason for the question is the following use case: we make use of the Flowable engine in cloud environment where blue-green deployments happen on a regular basis. In this case, temporarily, there are 2 times as many application nodes, as in a normal case. Half of them are excluded from the HTTP routing, though. But the background threads are still active for these nodes, making use of the sparse resources (e.g. DB or messaging connections). We would need to have more control over that.

Thank you!

Best regards,  
Vasil

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [February 4, 2020, 4:28pm UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/2 "2020-02-04T16:28:30Z")

</div>

Are these spring boot applications, if so it could simply be a matter of setting the property `flowable.process.async-executor-activate=false` and restarting the instances.

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [February 4, 2020, 4:51pm UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/3 "2020-02-04T16:51:15Z")

</div>

Thank you very much for the response! No, we don’t make use of spring boot.

BTW, we’ve come across the AsyncExecutor#shutdown function. How graceful is it?

Best regards,  
Vasil

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [February 4, 2020, 5:12pm UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/4 "2020-02-04T17:12:13Z")

</div>

Looking at the code in the [DefaultAsyncJobExecutor](https://github.com/flowable/flowable-engine/blob/master/modules/flowable-job-service/src/main/java/org/flowable/job/service/impl/asyncexecutor/DefaultAsyncJobExecutor.java), it looks like it gives executing jobs a minute to finish what they are doing:

```auto

    protected void stopExecutingAsyncJobs() {
        if (executorService != null) {

            // Ask the thread pool to finish and exit
            executorService.shutdown();

            // Waits for 1 minute to finish all currently executing jobs
            try {
                if (!executorService.awaitTermination(secondsToWaitOnShutdown, TimeUnit.SECONDS)) {
                    LOGGER.warn("Timeout during shutdown of async job executor. The current running jobs could not end within {} seconds after shutdown operation.",
                                    secondsToWaitOnShutdown);
                }
            } catch (InterruptedException e) {
                LOGGER.warn("Interrupted while shutting down the async job executor. ", e);
            }

            executorService = null;
        }
    }

```

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [February 4, 2020, 9:05pm UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/5 "2020-02-04T21:05:54Z")

</div>

shutdown() of the async executor is indeed gracefully (within the minute @wwitt is mentioning. This is a configurable timeout). We actually use this in unit tests to boot up and shut down the jobs to control exactly when jobs should be able to be picked up.

---

<div class="post-metadata">

**Author:** ![VasilTsimashchuk](https://avatars.discourse-cdn.com/v4/letter/v/ed655f/32.png) [@VasilTsimashchuk](https://forum.flowable.org/u/VasilTsimashchuk)\
**Post date:** [February 5, 2020, 8:50am UTC](https://forum.flowable.org/t/gracefully-switching-off-background-threads/5369/6 "2020-02-05T08:50:55Z")

</div>

Thank you @wwitt and @joram!  
We’ll make use of the functionality.
