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

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

Introduction

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

Prototype

ThreadPoolTaskExecutor

Source Link

Usage

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);//  w w w  . j  a  v  a 2s .com
    executor.setQueueCapacity(Integer.MAX_VALUE);
    executor.setAllowCoreThreadTimeOut(true);

    return executor;
}

From source file:org.openbaton.nfvo.core.api.NetworkServiceRecordManagement.java

@PostConstruct
private void init() {
    if (removeAfterTimeout) {
        asyncExecutor = new ThreadPoolTaskExecutor();
        asyncExecutor.setThreadNamePrefix("OpenbatonTask-");
        asyncExecutor.setMaxPoolSize(30);
        asyncExecutor.setCorePoolSize(5);
        asyncExecutor.setQueueCapacity(0);
        asyncExecutor.setKeepAliveSeconds(20);
        asyncExecutor.initialize();//from  ww  w  . j ava2 s.co m
    }
}

From source file:com.teradata.benchto.driver.DriverApp.java

@Bean
public ThreadPoolTaskExecutor defaultTaskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(5);/*from  w  w w . j a v  a  2s. c  om*/
    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
    taskExecutor.setAwaitTerminationSeconds(300);

    return taskExecutor;
}

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   www  . j  a va2 s.  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.bt.aloha.call.MaxCallDurationTerminationTest.java

@Test
public void testInitializeWithOneTermination() {
    // setup/*from w  w  w.ja v a2s.  co m*/
    ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
    te.initialize();
    maxCallDurationTermination.setTaskExecutor(te);
    callInfo = new CallInfo("test", CALL_ID_SET_TO_TERMINATE_IN_PAST, "1", "2", AutoTerminateAction.False, 1);
    if (!callInfo.setStartTime(System.currentTimeMillis() - FIVE_MINUTES_IN_MILLISECONDS))
        throw new RuntimeException("Can't set time in the past for some reason");
    callInfo.setCallState(CallState.Connected);
    callCollection.add(callInfo);
    maxCallDurationTermination.setCallBean(callBean);

    // act
    maxCallDurationTermination.runTask();
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } // allow time for thread to run

    // assert
    assertTrue(terminateWithReason);
}

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

/**
 * Creates a connection instance based on the supplied type.
 * //from  w  ww.  j a  v  a2  s . c  om
 * @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.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java

@Test
public void testImportWordList_LeftoversFromBatch() {
    ThreadPoolTaskExecutor taskExecutorSpy = spy(new ThreadPoolTaskExecutor());
    taskExecutorSpy.setCorePoolSize(4);//  www.j av  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));
}

From source file:org.ng200.openolympus.Application.java

@Bean
public ThreadPoolTaskExecutor taskExecutor() {
    final ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.setCorePoolSize(5);/*w w w .j av  a2  s. com*/
    pool.setMaxPoolSize(10);
    pool.setWaitForTasksToCompleteOnShutdown(true);
    return pool;
}

From source file:org.openbaton.nfvo.vnfm_reg.VnfmManager.java

@Override
@PostConstruct//from w  ww  .  jav a 2s  .  c  o  m
public void init() {

    log.debug("Running VnfmManager init");

    vnfrNames = new LinkedHashMap<>();
    /**
     * Asynchronous thread executor configuration
     */
    this.asyncExecutor = new ThreadPoolTaskExecutor();

    this.asyncExecutor.setThreadNamePrefix("OpenbatonTask-");

    this.asyncExecutor.setMaxPoolSize(maxPoolSize);
    this.asyncExecutor.setCorePoolSize(corePoolSize);
    this.asyncExecutor.setQueueCapacity(queueCapacity);
    this.asyncExecutor.setKeepAliveSeconds(keepAliveSeconds);

    this.asyncExecutor.initialize();

    log.debug("AsyncExecutor is: " + asyncExecutor);

    log.trace("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    log.trace("ThreadPollTaskExecutor configuration:");
    log.trace("MaxPoolSize = " + this.asyncExecutor.getMaxPoolSize());
    log.trace("CorePoolSize = " + this.asyncExecutor.getCorePoolSize());
    log.trace("QueueCapacity = " + this.asyncExecutor.getThreadPoolExecutor().getQueue().size());
    log.trace("KeepAlive = " + this.asyncExecutor.getKeepAliveSeconds());
    log.trace("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}