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

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

Introduction

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

Prototype

public void setQueueCapacity(int queueCapacity) 

Source Link

Document

Set the capacity for the ThreadPoolExecutor's BlockingQueue.

Usage

From source file:nl.pinniq.web.config.WebMvcConfiguration.java

@Bean
public ThreadPoolTaskExecutor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);/*  w  ww.j  a v a 2s .c  o m*/
    executor.setBeanName("threadPoolTaskExecutor");
    executor.setMaxPoolSize(50);
    executor.setQueueCapacity(10);
    executor.setThreadNamePrefix("MyExecutor-");
    executor.initialize();
    return executor;
}

From source file:org.bremersee.common.spring.autoconfigure.SchedulingAutoConfiguration.java

@Bean(name = { "taskExecutor", "metricsExecutor" })
@Primary/*from w ww  .  j ava  2  s  .  c o  m*/
public Executor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(properties.getTaskExecutorCorePoolSize());
    executor.setMaxPoolSize(properties.getTaskExecutorMaxPoolSize());
    executor.setQueueCapacity(properties.getTaskExecutorQueueCapacity());
    executor.setThreadNamePrefix(properties.getTaskExecutorThreadNamePrefix());
    executor.initialize();
    return executor;
}

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>
 *//* www.j  a  v a2  s .c om*/
@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:com.google.cloud.trace.zipkin.autoconfigure.ZipkinStackdriverStorageAutoConfiguration.java

@Bean(name = "stackdriverExecutor")
@ConditionalOnMissingBean(Executor.class)
Executor executor() {//from  w w w. j av  a2s .co m
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("ZipkinStackdriverStorage-");
    executor.setCorePoolSize(storageProperties.getExecutor().getCorePoolSize());
    executor.setMaxPoolSize(storageProperties.getExecutor().getMaxPoolSize());
    executor.setQueueCapacity(storageProperties.getExecutor().getQueueCapacity());
    executor.initialize();

    log.info("Configured Executor for ZipkinStackDriver Storage with: {}", storageProperties.getExecutor());
    return executor;
}

From source file:org.red5.client.net.rtmp.RTMPConnManager.java

/**
 * Creates a connection instance based on the supplied type.
 * //from  w w w. j av  a2 s  . c  o  m
 * @param cls
 * @return connection
 * @throws Exception
 */
public RTMPConnection createConnectionInstance(Class<?> cls) throws Exception {
    RTMPConnection conn = null;
    if (cls == RTMPMinaConnection.class) {
        conn = (RTMPMinaConnection) cls.newInstance();
    } else if (cls == RTMPTClientConnection.class) {
        conn = (RTMPTClientConnection) cls.newInstance();
    } else {
        conn = (RTMPConnection) cls.newInstance();
    }
    conn.setMaxHandshakeTimeout(maxHandshakeTimeout);
    conn.setMaxInactivity(maxInactivity);
    conn.setPingInterval(pingInterval);
    // setup executor
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(1);
    executor.setDaemon(true);
    executor.setMaxPoolSize(1);
    executor.setQueueCapacity(executorQueueCapacity);
    executor.initialize();
    conn.setExecutor(executor);
    return conn;
}

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 w  w .  ja  va  2s. c  o  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:org.apache.servicemix.jbi.cluster.engine.AbstractClusterEndpointTest.java

protected TaskExecutor createTaskExecutor() {
    ThreadPoolTaskExecutor exec = new CleanThreadPoolTaskExecutor();
    exec.setWaitForTasksToCompleteOnShutdown(true);
    exec.setQueueCapacity(0);
    exec.afterPropertiesSet();//  w  w  w . j  av  a2s.co  m
    return exec;
}

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

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

From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java

@Test
public void testImportWordList() {
    ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor());
    taskExecutorSpy.setCorePoolSize(4);//  ww w  .j  a v  a 2s .c o  m
    taskExecutorSpy.setMaxPoolSize(4);
    taskExecutorSpy.setQueueCapacity(100);
    taskExecutorSpy.setKeepAliveSeconds(1);
    taskExecutorSpy.setAllowCoreThreadTimeOut(true);
    taskExecutorSpy.initialize();

    WordListImporterImpl wordListImporterImpl = new WordListImporterImpl();
    wordListImporterImpl.setTaskExecutor(taskExecutorSpy);

    Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount");
    ReflectionUtils.makeAccessible(rowCountField);
    AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField,
            wordListImporterImpl);

    assertEquals(0, rowCountFromObject.intValue());

    WordDao wordDaoMock = mock(WordDao.class);
    when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true);
    int persistenceBatchSizeToSet = 3;
    int concurrencyBatchSizeToSet = 3;

    wordListImporterImpl.setWordDao(wordDaoMock);
    wordListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet);
    wordListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet);

    Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN));
    Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN));
    Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN));
    List<Word> wordsToReturn = new ArrayList<Word>();
    wordsToReturn.add(word1);
    wordsToReturn.add(word2);
    wordsToReturn.add(word3);
    PartOfSpeechFileParser fileParserMock = mock(PartOfSpeechFileParser.class);
    when(fileParserMock.parseFile()).thenReturn(wordsToReturn);

    wordListImporterImpl.setFileParser(fileParserMock);

    wordListImporterImpl.importWordList();

    rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl);

    assertEquals(3, rowCountFromObject.intValue());
    verify(wordDaoMock, times(1)).insertBatch(anyListOf(Word.class));
    verify(taskExecutorSpy, times(1)).execute(any(Runnable.class));
}

From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java

@Test
public void testImportWordList_LeftoversFromBatch() {
    ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor());
    taskExecutorSpy.setCorePoolSize(4);//from   ww  w  .ja v  a 2  s . co  m
    taskExecutorSpy.setMaxPoolSize(4);
    taskExecutorSpy.setQueueCapacity(100);
    taskExecutorSpy.setKeepAliveSeconds(1);
    taskExecutorSpy.setAllowCoreThreadTimeOut(true);
    taskExecutorSpy.initialize();

    WordListImporterImpl wordListImporterImpl = new WordListImporterImpl();
    wordListImporterImpl.setTaskExecutor(taskExecutorSpy);

    Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount");
    ReflectionUtils.makeAccessible(rowCountField);
    AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField,
            wordListImporterImpl);

    assertEquals(0, rowCountFromObject.intValue());

    WordDao wordDaoMock = mock(WordDao.class);
    when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true);
    int persistenceBatchSizeToSet = 3;
    int concurrencyBatchSizeToSet = 2;

    wordListImporterImpl.setWordDao(wordDaoMock);
    wordListImporterImpl.setPersistenceBatchSize(persistenceBatchSizeToSet);
    wordListImporterImpl.setConcurrencyBatchSize(concurrencyBatchSizeToSet);

    Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN));
    Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN));
    Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN));
    List<Word> wordsToReturn = new ArrayList<Word>();
    wordsToReturn.add(word1);
    wordsToReturn.add(word2);
    wordsToReturn.add(word3);
    PartOfSpeechFileParser fileParserMock = mock(PartOfSpeechFileParser.class);
    when(fileParserMock.parseFile()).thenReturn(wordsToReturn);

    wordListImporterImpl.setFileParser(fileParserMock);

    wordListImporterImpl.importWordList();

    rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl);

    assertEquals(3, rowCountFromObject.intValue());
    verify(wordDaoMock, times(2)).insertBatch(anyListOf(Word.class));
    verify(taskExecutorSpy, times(2)).execute(any(Runnable.class));
}