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

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

Introduction

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

Prototype

@Override
    public void setThreadNamePrefix(@Nullable String threadNamePrefix) 

Source Link

Usage

From source file:py.una.pol.karaku.configuration.AsyncConfiguration.java

/**
 * Crea un nuevo executor. Vase {@link #getAsyncExecutor()}
 *
 * @return {@link Executor} de tareas asncronas
 * @see <a href="http://appcia.cnc.una.py/wf/index.php/Asyn_task">Wiki</a>
 */// ww  w  .  j av a2  s.  c o  m
@Bean
public AsyncTaskExecutor asyncExecutor() {

    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(getInt("karaku.async.pool.size", DEFAULT_CORE_POOL_SIZE));
    executor.setMaxPoolSize(getInt("karaku.async.pool.max_size", DEFAULT_CORE_POOL_MAX_SIZE));
    executor.setQueueCapacity(getInt("karaku.async.queue.size", DEFAULT_ASYNC_QUEUE_SIZE));
    executor.setThreadNamePrefix(properties.get("karaku.async.thread.prefix", DEFAULT_THREAD_PREFIX));
    // TODO cambiar por un SyncTaskExecutor
    return executor;
}

From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java

@Bean
public Executor clientInboundChannelExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("wampClientInboundChannel-");
    executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
    executor.setMaxPoolSize(Integer.MAX_VALUE);
    executor.setKeepAliveSeconds(60);/*from   w  w  w .ja  va 2s. c  om*/
    executor.setQueueCapacity(Integer.MAX_VALUE);
    executor.setAllowCoreThreadTimeOut(true);

    return executor;
}

From source file:ch.rasc.wampspring.config.DefaultWampConfiguration.java

@Bean
public Executor clientOutboundChannelExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("wampClientOutboundChannel-");
    executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
    executor.setMaxPoolSize(Integer.MAX_VALUE);
    executor.setKeepAliveSeconds(60);/*from  w ww . ja  v  a2  s .co m*/
    executor.setQueueCapacity(Integer.MAX_VALUE);
    executor.setAllowCoreThreadTimeOut(true);

    return executor;
}

From source file:org.logger.event.web.controller.EventController.java

@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(15);//from ww w .j a va2 s.  com
    executor.setMaxPoolSize(80);
    executor.setQueueCapacity(200);
    executor.setThreadNamePrefix("eventExecutor");
    executor.initialize();
    return executor;
}

From source file:com.netflix.genie.common.internal.configs.AwsAutoConfiguration.java

/**
 * Provide an protocol resolver which will allow resources with s3:// prefixes to be resolved by the
 * application {@link org.springframework.core.io.ResourceLoader} provided this bean is eventually added to the
 * context via the/*from w ww.j a  v a  2s  .co  m*/
 * {@link org.springframework.context.ConfigurableApplicationContext#addProtocolResolver(ProtocolResolver)}
 * method.
 *
 * @param resourceLoaderProperties The {@link AwsS3ResourceLoaderProperties} instance to use
 * @param s3ClientFactory          The {@link S3ClientFactory} instance to use
 * @return A {@link S3ProtocolResolver} instance
 */
@Bean
@ConditionalOnMissingBean(S3ProtocolResolver.class)
public S3ProtocolResolver s3ProtocolResolver(final AwsS3ResourceLoaderProperties resourceLoaderProperties,
        final S3ClientFactory s3ClientFactory) {
    final ThreadPoolTaskExecutor s3TaskExecutor = new ThreadPoolTaskExecutor();
    s3TaskExecutor.setCorePoolSize(resourceLoaderProperties.getCorePoolSize());
    s3TaskExecutor.setMaxPoolSize(resourceLoaderProperties.getMaxPoolSize());
    s3TaskExecutor.setQueueCapacity(resourceLoaderProperties.getQueueCapacity());
    s3TaskExecutor.setThreadGroupName("Genie-S3-Resource-Loader-Thread-Pool");
    s3TaskExecutor.setThreadNamePrefix("S3-resource-loader-thread");
    return new S3ProtocolResolver(s3ClientFactory, s3TaskExecutor);
}

From source file:com.ethlo.geodata.GeodataServiceImpl.java

public void load() {
    ensureBaseDirectory();/* www.  j a v  a2  s.  co m*/

    final SourceDataInfoSet sourceInfo = geoMetaService.getSourceDataInfo();
    if (sourceInfo.isEmpty()) {
        logger.error(
                "Cannot start geodata server as there is no data. Please run with 'update' parameter to import data");
        System.exit(1);
    }

    loadHierarchy();

    final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(3);
    taskExecutor.setThreadNamePrefix("data-loading-");
    taskExecutor.initialize();

    taskExecutor.execute(this::loadLocations);
    taskExecutor.execute(this::loadMbr);
    taskExecutor.execute(this::loadIps);

    taskExecutor.setAwaitTerminationSeconds(Integer.MAX_VALUE);
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
    taskExecutor.shutdown();

    //final ResultSet<GeoLocation> result = geoNamesRepository.retrieve(QueryFactory.equal(CqGeonamesRepository.ATTRIBUTE_FEATURE_CODE, "ADM1"));
    //result.forEach(this::connectAdm1WithCountry);

    publisher.publishEvent(new DataLoadedEvent(this, DataType.ALL, Operation.LOAD, 1, 1));
}

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  va2  s  . c  om*/
    taskExecutor.setCorePoolSize(2);
    taskExecutor.setMaxPoolSize(3);
    taskExecutor.setThreadNamePrefix("Gemini Blueprint context shutdown thread");
    taskExecutor.afterPropertiesSet();
    isShutdownTaskExecutorManagedInternally = true;
    return taskExecutor;
}

From source file:org.flockdata.helper.ExecutorHelper.java

public static Executor getExecutor(String name, String poolSize, int qCapacity) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    String vals[] = StringUtils.split(poolSize, "-");

    executor.setCorePoolSize(Integer.parseInt(vals[0]));
    if (vals.length == 2)
        executor.setMaxPoolSize(Integer.parseInt(vals[1]));
    else/*from  w w  w. j a  va2s  .  co  m*/
        executor.setMaxPoolSize(Integer.parseInt(vals[0]));
    executor.setQueueCapacity(qCapacity);
    executor.setThreadNamePrefix(name + "-");
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();
    return executor.getThreadPoolExecutor();
}

From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java

@Test
public void testSimple() throws Exception {
    CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("client-");
    executor.afterPropertiesSet();/*from   www  .  j  av a 2  s.  co m*/
    cf.setExecutor(executor);
    DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
    container.setQueueNames(Q1, Q2);
    container.setConsumersPerQueue(2);
    container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
        if ("foo".equals(in) || "bar".equals(in)) {
            return in.toUpperCase();
        } else {
            return null;
        }
    }));
    container.setBeanName("simple");
    container.setConsumerTagStrategy(new Tag());
    container.afterPropertiesSet();
    container.start();
    RabbitTemplate template = new RabbitTemplate(cf);
    assertEquals("FOO", template.convertSendAndReceive(Q1, "foo"));
    assertEquals("BAR", template.convertSendAndReceive(Q2, "bar"));
    container.stop();
    assertTrue(consumersOnQueue(Q1, 0));
    assertTrue(consumersOnQueue(Q2, 0));
    assertTrue(activeConsumerCount(container, 0));
    assertEquals(0, TestUtils.getPropertyValue(container, "consumersByQueue", MultiValueMap.class).size());
    template.stop();
    cf.destroy();
}

From source file:org.springframework.amqp.rabbit.listener.DirectMessageListenerContainerIntegrationTests.java

@Test
public void testQueueManagement() throws Exception {
    CachingConnectionFactory cf = new CachingConnectionFactory("localhost");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("client-");
    executor.afterPropertiesSet();/*from  w w  w .java2 s  . c o m*/
    cf.setExecutor(executor);
    DirectMessageListenerContainer container = new DirectMessageListenerContainer(cf);
    container.setConsumersPerQueue(2);
    container.setMessageListener(new MessageListenerAdapter((ReplyingMessageListener<String, String>) in -> {
        if ("foo".equals(in) || "bar".equals(in)) {
            return in.toUpperCase();
        } else {
            return null;
        }
    }));
    container.setBeanName("qManage");
    container.setConsumerTagStrategy(new Tag());
    container.afterPropertiesSet();
    container.start();
    container.addQueueNames(Q1, Q2);
    assertTrue(consumersOnQueue(Q1, 2));
    assertTrue(consumersOnQueue(Q2, 2));
    RabbitTemplate template = new RabbitTemplate(cf);
    assertEquals("FOO", template.convertSendAndReceive(Q1, "foo"));
    assertEquals("BAR", template.convertSendAndReceive(Q2, "bar"));
    container.removeQueueNames(Q1, Q2, "junk");
    assertTrue(consumersOnQueue(Q1, 0));
    assertTrue(consumersOnQueue(Q2, 0));
    assertTrue(activeConsumerCount(container, 0));
    container.stop();
    assertTrue(consumersOnQueue(Q1, 0));
    assertTrue(consumersOnQueue(Q2, 0));
    assertTrue(activeConsumerCount(container, 0));
    assertEquals(0, TestUtils.getPropertyValue(container, "consumersByQueue", MultiValueMap.class).size());
    template.stop();
    cf.destroy();
}