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

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

Introduction

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

Prototype

public void setCorePoolSize(int corePoolSize) 

Source Link

Document

Set the ThreadPoolExecutor's core pool size.

Usage

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  a 2  s.  c  o  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: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. jav a 2  s .  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:com.project.atm.http.util.HttpExecutor.java

public HttpExecutor(ThreadPoolTaskExecutor taskExecutor) {
    this.taskExecutor = taskExecutor;

    String httpThread = ResourceHelper.getAppResource("httpThread");
    if (httpThread.isEmpty() || httpThread.equals("")) {
        taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
    } else {// w  w w. jav  a  2s  . c  o  m
        try {
            taskExecutor.setCorePoolSize(Integer.parseInt(httpThread));
        } catch (NumberFormatException nfe) {
            logger.error(nfe.getMessage() + ", set to default configuration");
            taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
        }
    }
}

From source file:access.Application.java

@Override
@Bean/* w  w w.jav  a2s  .  c o m*/
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(threadCountSize);
    executor.setMaxPoolSize(threadCountLimit);
    executor.initialize();
    return executor;
}

From source file:com.project.atm.model.async.ProcessExecutor.java

public ProcessExecutor(ThreadPoolTaskExecutor taskExecutor) {
    this.taskExecutor = taskExecutor;

    String processThread = ResourceHelper.getAppResource("processThread");
    if (processThread.isEmpty() || processThread.equals("")) {
        taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
    } else {//from  ww  w.  j  a  v a 2  s.  co m
        try {
            taskExecutor.setCorePoolSize(Integer.parseInt(processThread));
        } catch (NumberFormatException nfe) {
            logger.error(nfe.getMessage() + ", set to default configuration");
            taskExecutor.setCorePoolSize(Runtime.getRuntime().availableProcessors() / 2);
        }
    }

}

From source file:com.netflix.genie.web.configs.GenieTasksAutoConfiguration.java

/**
 * Get a task executor for executing tasks asynchronously that don't need to be scheduled at a recurring rate.
 *
 * @param tasksExecutorPoolProperties The properties for the task executor thread pool
 * @return The task executor the system to use
 *//*from  w  w  w .  jav a2  s.c  o  m*/
@Bean
@ConditionalOnMissingBean(name = "genieAsyncTaskExecutor")
public AsyncTaskExecutor genieAsyncTaskExecutor(final TasksExecutorPoolProperties tasksExecutorPoolProperties) {
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(tasksExecutorPoolProperties.getSize());
    executor.setThreadNamePrefix(tasksExecutorPoolProperties.getThreadNamePrefix());
    return executor;
}

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

/**
 * Creates a connection instance based on the supplied type.
 * /*from   ww  w  .java 2s . 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:org.logger.event.web.controller.EventController.java

@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(15);
    executor.setMaxPoolSize(80);/*from ww  w.j a  va  2  s.  c o  m*/
    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);
    taskExecutorSpy.setMaxPoolSize(4);/*  w w  w  .  ja v  a  2s.  c o m*/
    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));
}