这可能还是由Application Server管理?将ThreadPoolTaskExecutor引用传递给bean是不费脑子的但是试图在上述执行器上设置threadfactory似乎没有效果......
答案 0 :(得分:6)
实际上,设置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)
的位置。