Search in sources :

Example 16 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.

the class TestValidator method testExecutor.

private void testExecutor(String channelName, int corePoolSize, int maxPoolSize, int keepAliveSeconds) {
    ThreadPoolTaskExecutor taskExecutor = this.appContext.getBean(channelName + "Executor", ThreadPoolTaskExecutor.class);
    assertEquals(corePoolSize, taskExecutor.getCorePoolSize());
    assertEquals(maxPoolSize, taskExecutor.getMaxPoolSize());
    assertEquals(keepAliveSeconds, taskExecutor.getKeepAliveSeconds());
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 17 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method clientInboundChannelExecutor.

@Bean
public ThreadPoolTaskExecutor clientInboundChannelExecutor() {
    TaskExecutorRegistration reg = getClientInboundChannelRegistration().getOrCreateTaskExecRegistration();
    ThreadPoolTaskExecutor executor = reg.getTaskExecutor();
    executor.setThreadNamePrefix("clientInboundChannel-");
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 18 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.

the class TaskExecutorFactoryBean method afterPropertiesSet.

@Override
public void afterPropertiesSet() {
    this.target = new ThreadPoolTaskExecutor();
    determinePoolSizeRange();
    if (this.queueCapacity != null) {
        this.target.setQueueCapacity(this.queueCapacity);
    }
    if (this.keepAliveSeconds != null) {
        this.target.setKeepAliveSeconds(this.keepAliveSeconds);
    }
    if (this.rejectedExecutionHandler != null) {
        this.target.setRejectedExecutionHandler(this.rejectedExecutionHandler);
    }
    if (this.beanName != null) {
        this.target.setThreadNamePrefix(this.beanName + "-");
    }
    this.target.afterPropertiesSet();
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 19 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.

the class AsyncAnnotationBeanPostProcessorTests method threadNamePrefix.

@Test
public void threadNamePrefix() {
    BeanDefinition processorDefinition = new RootBeanDefinition(AsyncAnnotationBeanPostProcessor.class);
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("testExecutor");
    executor.afterPropertiesSet();
    processorDefinition.getPropertyValues().add("executor", executor);
    ConfigurableApplicationContext context = initContext(processorDefinition);
    ITestBean testBean = context.getBean("target", ITestBean.class);
    testBean.test();
    testBean.await(3000);
    Thread asyncThread = testBean.getThread();
    assertTrue(asyncThread.getName().startsWith("testExecutor"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Test(org.junit.Test)

Example 20 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-framework by spring-projects.

the class MessageBrokerConfigurationTests method threadPoolSizeDefault.

@Test
public void threadPoolSizeDefault() {
    String name = "clientInboundChannelExecutor";
    ThreadPoolTaskExecutor executor = this.defaultContext.getBean(name, ThreadPoolTaskExecutor.class);
    assertEquals(Runtime.getRuntime().availableProcessors() * 2, executor.getCorePoolSize());
    // No way to verify queue capacity
    name = "clientOutboundChannelExecutor";
    executor = this.defaultContext.getBean(name, ThreadPoolTaskExecutor.class);
    assertEquals(Runtime.getRuntime().availableProcessors() * 2, executor.getCorePoolSize());
    name = "brokerChannelExecutor";
    executor = this.defaultContext.getBean(name, ThreadPoolTaskExecutor.class);
    assertEquals(0, executor.getCorePoolSize());
    assertEquals(1, executor.getMaxPoolSize());
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)24 Test (org.junit.Test)8 Bean (org.springframework.context.annotation.Bean)8 Random (java.util.Random)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 AbstractSubscribableChannel (org.springframework.messaging.support.AbstractSubscribableChannel)2 Brave (com.github.kristofa.brave.Brave)1 ServerSpan (com.github.kristofa.brave.ServerSpan)1 ServerSpanState (com.github.kristofa.brave.ServerSpanState)1 Endpoint (com.twitter.zipkin.gen.Endpoint)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 ByteBuffer (java.nio.ByteBuffer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 FutureTask (java.util.concurrent.FutureTask)1 CamelThreadFactory (org.apache.camel.util.concurrent.CamelThreadFactory)1 ExecuteContext (org.jooq.ExecuteContext)1 ExecuteListenerProvider (org.jooq.ExecuteListenerProvider)1