Browse Source

SPR-6644 The 'id' value from an 'executor' element in the task namespace is now used as the thread name prefix for the resulting ThreadPoolTaskExecutor instance.

pull/23217/head
Mark Fisher 16 years ago
parent
commit
4ab4fa7042
  1. 3
      org.springframework.context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java
  2. 8
      org.springframework.context/src/test/java/org/springframework/scheduling/config/ExecutorBeanDefinitionParserTests.java

3
org.springframework.context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java

@ -108,6 +108,9 @@ public class TaskExecutorFactoryBean implements FactoryBean<TaskExecutor>, BeanN @@ -108,6 +108,9 @@ public class TaskExecutorFactoryBean implements FactoryBean<TaskExecutor>, BeanN
this.setValueIfNotNull("corePoolSize", range[0]);
this.setValueIfNotNull("maxPoolSize", range[1]);
}
if (this.beanName != null) {
this.beanWrapper.setPropertyValue("threadNamePrefix", this.beanName + "-");
}
this.target = (TaskExecutor) this.beanWrapper.getWrappedInstance();
if (this.target instanceof InitializingBean) {
((InitializingBean)this.target).afterPropertiesSet();

8
org.springframework.context/src/test/java/org/springframework/scheduling/config/ExecutorBeanDefinitionParserTests.java

@ -19,7 +19,6 @@ package org.springframework.scheduling.config; @@ -19,7 +19,6 @@ package org.springframework.scheduling.config;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import org.junit.Before;
@ -30,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException; @@ -30,6 +29,7 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.CustomizableThreadCreator;
/**
* @author Mark Fisher
@ -124,6 +124,12 @@ public class ExecutorBeanDefinitionParserTests { @@ -124,6 +124,12 @@ public class ExecutorBeanDefinitionParserTests {
this.context.getBean("propertyPlaceholderWithInvalidPoolSize");
}
@Test
public void threadNamePrefix() {
CustomizableThreadCreator executor = this.context.getBean("default", CustomizableThreadCreator.class);
assertEquals("default-", executor.getThreadNamePrefix());
}
private int getCorePoolSize(Object executor) {
return (Integer) new DirectFieldAccessor(executor).getPropertyValue("corePoolSize");

Loading…
Cancel
Save