gpt4 book ai didi

java - Spring 3 为 ThreadPoolTask​​Executor 设置 ThreadFactory

转载 作者:搜寻专家 更新时间:2023-10-31 19:57:30 31 4
gpt4 key购买 nike

这是可能的还是由应用服务器管理?将 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-");
}

请注意 ThreadPoolTaskExecutorExecutorConfigurationSupport 延伸这就是setThreadFactory(java.util.concurrent.ThreadFactory)已定义。

关于java - Spring 3 为 ThreadPoolTask​​Executor 设置 ThreadFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9471509/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com