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:Main.java

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

From source file:com.netflix.spinnaker.orca.config.JedisConfiguration.java

private static ThreadPoolTaskExecutor newFixedThreadPool(int threadPoolSize) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(threadPoolSize);
    executor.setMaxPoolSize(threadPoolSize);
    return executor;
}

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.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.cloudfoundry.caldecott.client.TunnelServer.java

protected static TaskExecutor getDefaultThreadExecutor() {
    ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
    te.setCorePoolSize(5);
    te.setMaxPoolSize(10);/*w w w.ja  v a  2 s  . co m*/
    te.setQueueCapacity(100);
    return te;
}

From source file:com.ciphertool.zodiacengine.genetic.algorithms.ConcurrentBasicGeneticAlgorithmTest.java

@BeforeClass
public static void setUp() {
    FitnessEvaluator fitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator();
    fitnessEvaluator.setGeneticStructure(zodiac408);

    CrossoverAlgorithm crossoverAlgorithm = new LowestCommonGroupCrossoverAlgorithm();
    crossoverAlgorithm.setFitnessEvaluator(fitnessEvaluator);

    SingleSequenceMutationAlgorithm mutationAlgorithm = new SingleSequenceMutationAlgorithm();
    mutationAlgorithm.setSequenceDao(new PlaintextSequenceDao());

    ProbabilisticSelectionAlgorithm selectionAlgorithm = new ProbabilisticSelectionAlgorithm();

    Selector selector = new RouletteSelector();

    GeneticAlgorithmStrategy geneticAlgorithmStrategy = new GeneticAlgorithmStrategy(zodiac408, POPULATION_SIZE,
            LIFESPAN, MAX_GENERATIONS, SURVIVAL_RATE, MUTATION_RATE, MAX_MUTATIONS_PER_INDIVIDUAL,
            CROSSOVER_RATE, MUTATE_DURING_CROSSOVER, fitnessEvaluator, crossoverAlgorithm, mutationAlgorithm,
            selectionAlgorithm, selector);

    population.setBreeder(solutionBreederMock);
    population.setSelector(selector);/*from  w  w  w.  j  a v  a 2  s . com*/

    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(MAX_THREADS);
    taskExecutor.setMaxPoolSize(MAX_THREADS);
    taskExecutor.setQueueCapacity(THREAD_EXECUTOR_QUEUE_CAPACITY);
    taskExecutor.setKeepAliveSeconds(1);
    taskExecutor.setAllowCoreThreadTimeOut(true);
    taskExecutor.initialize();

    population.setTaskExecutor(taskExecutor);

    geneticAlgorithm = new ConcurrentBasicGeneticAlgorithm();
    geneticAlgorithm.setPopulation(population);
    geneticAlgorithm.setStrategy(geneticAlgorithmStrategy);
    ((ConcurrentBasicGeneticAlgorithm) geneticAlgorithm).setTaskExecutor(taskExecutor);

    ExecutionStatisticsDao executionStatisticsDaoMock = mock(ExecutionStatisticsDao.class);
    ((ConcurrentBasicGeneticAlgorithm) geneticAlgorithm).setExecutionStatisticsDao(executionStatisticsDaoMock);
}

From source file:com.ciphertool.zodiacengine.genetic.PopulationTest.java

@BeforeClass
public static void setUp() {
    population.setSelector(new RouletteSelector());

    population.setBreeder(solutionBreederMock);

    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(4);
    taskExecutor.setMaxPoolSize(4);//from   w ww. j a  v  a  2s . c om
    taskExecutor.setQueueCapacity(100);
    taskExecutor.setKeepAliveSeconds(1);
    taskExecutor.setAllowCoreThreadTimeOut(true);
    taskExecutor.initialize();

    population.setTaskExecutor(taskExecutor);

    CipherSolutionKnownSolutionFitnessEvaluator cipherSolutionKnownSolutionFitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator();
    cipherSolutionKnownSolutionFitnessEvaluator.setGeneticStructure(zodiac408);
    population.setFitnessEvaluator(cipherSolutionKnownSolutionFitnessEvaluator);

    population.setLifespan(LIFESPAN);
    population.setFitnessComparator(new AscendingFitnessComparator());

    dummySolution = knownSolution.clone();
    dummySolution.getGenes().get(0).insertSequence(0,
            new PlaintextSequence(0, "i", dummySolution.getGenes().get(0)));
}

From source file:com.ciphertool.zodiacengine.genetic.algorithms.BasicGeneticAlgorithmTest.java

@BeforeClass
public static void setUp() {
    FitnessEvaluator fitnessEvaluator = new CipherSolutionKnownSolutionFitnessEvaluator();
    fitnessEvaluator.setGeneticStructure(zodiac408);

    CrossoverAlgorithm crossoverAlgorithm = new LowestCommonGroupCrossoverAlgorithm();
    crossoverAlgorithm.setFitnessEvaluator(fitnessEvaluator);

    SingleSequenceMutationAlgorithm mutationAlgorithm = new SingleSequenceMutationAlgorithm();
    mutationAlgorithm.setSequenceDao(new PlaintextSequenceDao());

    ProbabilisticSelectionAlgorithm selectionAlgorithm = new ProbabilisticSelectionAlgorithm();

    Selector selector = new RouletteSelector();

    GeneticAlgorithmStrategy geneticAlgorithmStrategy = new GeneticAlgorithmStrategy(zodiac408, POPULATION_SIZE,
            LIFESPAN, MAX_GENERATIONS, SURVIVAL_RATE, MUTATION_RATE, MAX_MUTATIONS_PER_INDIVIDUAL,
            CROSSOVER_RATE, MUTATE_DURING_CROSSOVER, fitnessEvaluator, crossoverAlgorithm, mutationAlgorithm,
            selectionAlgorithm, selector);

    population.setBreeder(solutionBreederMock);
    population.setSelector(selector);/* ww  w.  j ava  2  s . com*/

    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(MAX_THREADS);
    taskExecutor.setMaxPoolSize(MAX_THREADS);
    taskExecutor.setQueueCapacity(THREAD_EXECUTOR_QUEUE_CAPACITY);
    taskExecutor.setKeepAliveSeconds(1);
    taskExecutor.setAllowCoreThreadTimeOut(true);
    taskExecutor.initialize();

    population.setTaskExecutor(taskExecutor);

    geneticAlgorithm = new BasicGeneticAlgorithm();
    geneticAlgorithm.setPopulation(population);
    geneticAlgorithm.setStrategy(geneticAlgorithmStrategy);

    ExecutionStatisticsDao executionStatisticsDaoMock = mock(ExecutionStatisticsDao.class);
    ((BasicGeneticAlgorithm) geneticAlgorithm).setExecutionStatisticsDao(executionStatisticsDaoMock);
}

From source file:com.aol.advertising.qiao.util.CommonUtils.java

public static ThreadPoolTaskExecutor createFixedThreadPoolExecutor(int threadPoolSize) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(threadPoolSize);
    executor.setMaxPoolSize(threadPoolSize);
    executor.setQueueCapacity(0);//w  ww .j  a  v  a 2 s  .c  o  m
    executor.setRejectedExecutionHandler(new CallerRunsPolicy());
    return executor;
}

From source file:com.aol.advertising.qiao.util.CommonUtils.java

public static ThreadPoolTaskExecutor createThreadPoolExecutor(int corePoolSize, int maxPoolSize,
        int queueCapacity) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setRejectedExecutionHandler(new CallerRunsPolicy());
    return executor;
}