这是可能的还是由Application Server管理?将ThreadPoolTaskExecutor引用传递给bean是不费脑子的但是尝试在上述执行器上设置threadfactory似乎没有效果……
解决方法:
实际上,设置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)
的位置.