На самом деле, установка ThreadFactory
также проста:
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="threadFactory" ref="threadFactory"/>
</bean>
<bean id="threadFactory" class="org.springframework.scheduling.concurrent.CustomizableThreadFactory">
<constructor-arg value="Custom-prefix-"/>
</bean>
или:
@Bean
public ThreadPoolTaskExecutor taskExecutor() {
final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setThreadFactory(threadFactory());
return taskExecutor;
}
@Bean
public ThreadFactory threadFactory() {
return new CustomizableThreadFactory("Custom-prefix-");
}
Обратите внимание, что ThreadPoolTaskExecutor
расширяетсяот ExecutorConfigurationSupport
, и именно здесь определяется setThreadFactory(java.util.concurrent.ThreadFactory)
.