Strange threadPool behaviour (too much creation)

I have simple config with timer start event, from config below I expect that my thread pool will have const size “2” but during tests I see threads creations( which confirm from logs, where I print thread name), what I’m doing wrong, why these threads did not reuse

start Fri Apr 23 09:53:33 CEST 2021 flowable-async-job-executor-thread-1
stop  Fri Apr 23 09:53:34 CEST 2021 flowable-async-job-executor-thread-1
start Fri Apr 23 09:54:02 CEST 2021 flowable-async-job-executor-thread-3
stop  Fri Apr 23 09:54:03 CEST 2021 flowable-async-job-executor-thread-3
start Fri Apr 23 09:54:32 CEST 2021 flowable-async-job-executor-thread-5
stop  Fri Apr 23 09:54:33 CEST 2021 flowable-async-job-executor-thread-5
start Fri Apr 23 09:55:03 CEST 2021 flowable-async-job-executor-thread-7
stop  Fri Apr 23 09:55:04 CEST 2021 flowable-async-job-executor-thread-7
start Fri Apr 23 09:55:33 CEST 2021 flowable-async-job-executor-thread-9
stop  Fri Apr 23 09:55:34 CEST 2021 flowable-async-job-executor-thread-9
start Fri Apr 23 09:56:03 CEST 2021 flowable-async-job-executor-thread-11
stop  Fri Apr 23 09:56:04 CEST 2021 flowable-async-job-executor-thread-11
start Fri Apr 23 09:56:33 CEST 2021 flowable-async-job-executor-thread-13
stop  Fri Apr 23 09:56:34 CEST 2021 flowable-async-job-executor-thread-13


	StandaloneProcessEngineConfiguration standaloneProcessEngineConfiguration = new StandaloneProcessEngineConfiguration();
	ProcessEngineConfiguration cfg = standaloneProcessEngineConfiguration.setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")

	ProcessEngine processEngine = cfg.setHistory(HistoryLevel.FULL.getKey()).setAsyncExecutorActivate(true).buildProcessEngine();

where business-tx-timer.bpmn20.xml:

<process id="timer">

		<startEvent id="theStart" flowable:async="true">
				<timeCycle>*/30 * * * * ?</timeCycle>
		<sequenceFlow sourceRef="theStart" targetRef="script" />
		<scriptTask id="script" name="Execute script2"
			scriptFormat="groovy" flowable:async="true">
				println 'start '+new Date()+' '+Thread.currentThread().getName()
				println 'stop  '+new Date()+' '+ Thread.currentThread().getName()
		<sequenceFlow sourceRef="script" targetRef="finalend" />
		<endEvent id="finalend" />

The JDK will destroy the threads after a while and create new ones, adding a new number at the end. But it guarantees no more than two will be active, ever. If you want to change the time before destroying the thread, you need to change the keepAlive setting.

You have right, I’m suprise,
For others I can turn it off by setAsyncExecutorAllowCoreThreadTimeout(false) or tune by asyncExecutorThreadKeepAliveTime (default 5000 milis)