Example usage for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor afterPropertiesSet

List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor afterPropertiesSet

Introduction

In this page you can find the example usage for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor afterPropertiesSet.

Prototype

@Override
public void afterPropertiesSet() 

Source Link

Document

Calls initialize() after the container applied all property values.

Usage

From source file:Main.java

public static ThreadPoolTaskExecutor defaultPool(int corePoolSize) {
    ThreadPoolTaskExecutor ex = new ThreadPoolTaskExecutor();
    ex.setCorePoolSize(corePoolSize);//from   w w  w .ja  v a2s. c o  m
    ex.setKeepAliveSeconds(60);
    ex.setThreadNamePrefix("defaultPool_");
    ex.afterPropertiesSet();
    return ex;
}

From source file:org.mimacom.sample.integration.patterns.user.service.integration.BulkHeadedSearchServiceIntegration.java

private static AsyncRestTemplate initializeRestTemplate(String threadNamePrefix) {
    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    threadPoolTaskExecutor.setCorePoolSize(2);
    threadPoolTaskExecutor.setMaxPoolSize(2);
    threadPoolTaskExecutor.setThreadNamePrefix(threadNamePrefix);
    threadPoolTaskExecutor.afterPropertiesSet();

    return new AsyncRestTemplate(threadPoolTaskExecutor);
}

From source file:org.mimacom.sample.integration.patterns.user.service.integration.AsyncSearchServiceIntegration.java

private static AsyncRestTemplate initializeRestTemplate() {
    ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
    threadPoolTaskExecutor.setCorePoolSize(2);
    threadPoolTaskExecutor.setMaxPoolSize(2);
    threadPoolTaskExecutor.setThreadNamePrefix("SearchServiceIntegration-");
    threadPoolTaskExecutor.afterPropertiesSet();

    return new AsyncRestTemplate(threadPoolTaskExecutor);
}

From source file:org.apache.camel.component.xquery.XQueryConcurrencyTest.java

@Test
public void testConcurrency() throws Exception {
    int total = 1000;

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);/*www  .ja v a 2 s  .c o m*/

    // 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(uri,
                            "<person><id>" + (start + i + 1) + "</id><name>James</name></person>");
                }
            }
        });
    }

    mock.assertNoDuplicates(body());

    assertMockEndpointsSatisfied();
    executor.shutdown();
}

From source file:org.apache.camel.component.xquery.XQueryURLBasedConcurrencyTest.java

@Test
public void testConcurrency() throws Exception {
    int total = 1000;

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);/*  w w  w.j  av  a 2s  . c om*/

    // 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();
}

From source file:eu.tripledframework.eventbus.autoconfigure.EventBusAutoConfiguration.java

private Executor taskExecutor() {
    ThreadPoolTaskExecutor executorService = new ThreadPoolTaskExecutor();
    executorService.setCorePoolSize(5);//w  w w.j  a  v a 2 s .  c  o  m
    executorService.setMaxPoolSize(10);

    executorService.afterPropertiesSet();
    return executorService;
}

From source file:de.codecentric.batch.configuration.TaskExecutorConfiguration.java

@Bean
public TaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new MdcThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(env.getProperty("batch.core.pool.size", Integer.class, 5));
    taskExecutor.setQueueCapacity(env.getProperty("batch.queue.capacity", Integer.class, Integer.MAX_VALUE));
    taskExecutor.setMaxPoolSize(env.getProperty("batch.max.pool.size", Integer.class, Integer.MAX_VALUE));
    taskExecutor.afterPropertiesSet();
    return taskExecutor;
}

From source file:org.apache.servicemix.jbi.cluster.engine.AbstractClusterEndpointTest.java

protected TaskExecutor createTaskExecutor() {
    ThreadPoolTaskExecutor exec = new CleanThreadPoolTaskExecutor();
    exec.setWaitForTasksToCompleteOnShutdown(true);
    exec.setQueueCapacity(0);/* w  w w.j a v  a 2s  . c  om*/
    exec.afterPropertiesSet();
    return exec;
}

From source file:org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration.java

private TaskExecutor createDefaultShutdownTaskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setDaemon(true);//from w  w  w  .  j a v  a 2  s .  c  o  m
    taskExecutor.setCorePoolSize(2);
    taskExecutor.setMaxPoolSize(3);
    taskExecutor.setThreadNamePrefix("Gemini Blueprint context shutdown thread");
    taskExecutor.afterPropertiesSet();
    isShutdownTaskExecutorManagedInternally = true;
    return taskExecutor;
}

From source file:org.springframework.amqp.rabbit.core.RabbitTemplateIntegrationTests.java

@Test
public void testAtomicSendAndReceiveExternalExecutor() throws Exception {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
    final String execName = "make-sure-exec-passed-in";
    exec.setBeanName(execName);//from   ww  w  .ja  v  a2 s. c o m
    exec.afterPropertiesSet();
    connectionFactory.setExecutor(exec);
    final Field[] fields = new Field[1];
    ReflectionUtils.doWithFields(RabbitTemplate.class, new FieldCallback() {
        public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
            field.setAccessible(true);
            fields[0] = field;
        }
    }, new FieldFilter() {
        public boolean matches(Field field) {
            return field.getName().equals("logger");
        }
    });
    Log logger = Mockito.mock(Log.class);
    when(logger.isTraceEnabled()).thenReturn(true);

    final AtomicBoolean execConfiguredOk = new AtomicBoolean();

    doAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            String log = (String) invocation.getArguments()[0];
            if (log.startsWith("Message received") && Thread.currentThread().getName().startsWith(execName)) {
                execConfiguredOk.set(true);
            }
            return null;
        }
    }).when(logger).trace(Mockito.anyString());
    final RabbitTemplate template = new RabbitTemplate(connectionFactory);
    ReflectionUtils.setField(fields[0], template, logger);
    template.setRoutingKey(ROUTE);
    template.setQueue(ROUTE);
    ExecutorService executor = Executors.newFixedThreadPool(1);
    // Set up a consumer to respond to our producer
    Future<Message> received = executor.submit(new Callable<Message>() {

        public Message call() throws Exception {
            Message message = null;
            for (int i = 0; i < 10; i++) {
                message = template.receive();
                if (message != null) {
                    break;
                }
                Thread.sleep(100L);
            }
            assertNotNull("No message received", message);
            template.send(message.getMessageProperties().getReplyTo(), message);
            return message;
        }

    });
    Message message = new Message("test-message".getBytes(), new MessageProperties());
    Message reply = template.sendAndReceive(message);
    assertEquals(new String(message.getBody()),
            new String(received.get(1000, TimeUnit.MILLISECONDS).getBody()));
    assertNotNull("Reply is expected", reply);
    assertEquals(new String(message.getBody()), new String(reply.getBody()));
    // Message was consumed so nothing left on queue
    reply = template.receive();
    assertEquals(null, reply);

    assertTrue(execConfiguredOk.get());
}