Search in sources :

Example 6 with ThreadPoolTaskExecutor

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

the class AbstractMessageBrokerConfiguration method clientOutboundChannelExecutor.

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

Example 7 with ThreadPoolTaskExecutor

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

the class TaskExecutorRegistration method getTaskExecutor.

protected ThreadPoolTaskExecutor getTaskExecutor() {
    ThreadPoolTaskExecutor executor = (this.taskExecutor != null ? this.taskExecutor : new ThreadPoolTaskExecutor());
    executor.setCorePoolSize(this.corePoolSize);
    executor.setMaxPoolSize(this.maxPoolSize);
    executor.setKeepAliveSeconds(this.keepAliveSeconds);
    executor.setQueueCapacity(this.queueCapacity);
    executor.setAllowCoreThreadTimeOut(true);
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 8 with ThreadPoolTaskExecutor

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

the class GenericMessagingTemplateTests method setup.

@Before
public void setup() {
    this.messageChannel = new StubMessageChannel();
    this.template = new GenericMessagingTemplate();
    this.template.setDefaultDestination(this.messageChannel);
    this.template.setDestinationResolver(new TestDestinationResolver());
    this.executor = new ThreadPoolTaskExecutor();
    this.executor.afterPropertiesSet();
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) StubMessageChannel(org.springframework.messaging.StubMessageChannel) Before(org.junit.Before)

Example 9 with ThreadPoolTaskExecutor

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

the class MessageBrokerConfigurationTests method clientOutboundChannelCustomized.

@Test
public void clientOutboundChannelCustomized() {
    AbstractSubscribableChannel channel = this.customContext.getBean("clientOutboundChannel", AbstractSubscribableChannel.class);
    assertEquals(3, channel.getInterceptors().size());
    ThreadPoolTaskExecutor taskExecutor = this.customContext.getBean("clientOutboundChannelExecutor", ThreadPoolTaskExecutor.class);
    assertEquals(21, taskExecutor.getCorePoolSize());
    assertEquals(22, taskExecutor.getMaxPoolSize());
    assertEquals(23, taskExecutor.getKeepAliveSeconds());
}
Also used : AbstractSubscribableChannel(org.springframework.messaging.support.AbstractSubscribableChannel) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Test(org.junit.Test)

Example 10 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.

the class XQueryURLBasedConcurrencyTest method testConcurrency.

@Test
public void testConcurrency() throws Exception {
    int total = 1000;
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);
    // setup a task executor to be able send the messages in parallel
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.afterPropertiesSet();
    for (int i = 0; i < 5; i++) {
        final int threadCount = i;
        executor.execute(new Runnable() {

            public void run() {
                int start = threadCount * 200;
                for (int i = 0; i < 200; i++) {
                    try {
                        // do some random sleep to simulate spread in user activity
                        Thread.sleep(new Random().nextInt(10));
                    } catch (InterruptedException e) {
                    // ignore
                    }
                    template.sendBody("direct:start", "<mail><subject>" + (start + i) + "</subject><body>Hello world!</body></mail>");
                }
            }
        });
    }
    mock.assertIsSatisfied();
    // must use bodyAs(String.class) to force DOM to be converted to String XML
    // for duplication detection
    mock.assertNoDuplicates(bodyAs(String.class));
    executor.shutdown();
}
Also used : Random(java.util.Random) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) 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