这是可能的还是由Application Server管理?将ThreadPoolTask​​Executor ref传递给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) 的定义位置。

07-24 21:49