2012-02-27 9 views

risposta

6

In realtà, l'impostazione di un ThreadFactory è un gioco da ragazzi così:

<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> 

o:

@Bean 
public ThreadPoolTaskExecutor taskExecutor() { 
    final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); 
    taskExecutor.setThreadFactory(threadFactory()); 
    return taskExecutor; 
} 

@Bean 
public ThreadFactory threadFactory() { 
    return new CustomizableThreadFactory("Custom-prefix-"); 
} 

noti che ThreadPoolTaskExecutor estende da ExecutorConfigurationSupport ed è qui setThreadFactory(java.util.concurrent.ThreadFactory) è definita.

+0

Perfetto! Questo funziona. Grazie Tomasz. –