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: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);/* w  w w. ja  v a 2  s  . c o m*/

    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.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;
}

From source file:burstcoin.jminer.core.CoreConfig.java

/**
 * Network pool./* ww w .  j ava2  s  .c om*/
 *
 * @return the thread pool task executor
 */
@Bean(name = "networkPool")
public ThreadPoolTaskExecutor networkPool() {
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.setMaxPoolSize(2);
    pool.setThreadPriority(Thread.NORM_PRIORITY + 1);
    return pool;
}

From source file:zipkin.autoconfigure.storage.mysql.brave.TraceZipkinMySQLStorageAutoConfiguration.java

@Bean
@ConditionalOnMissingBean(Executor.class)
public Executor executor(ServerSpanState serverState) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("MySQLStorage-");
    executor.initialize();/*from  ww w.jav a2s  .c  om*/
    return command -> {
        ServerSpan currentSpan = serverState.getCurrentServerSpan();
        executor.execute(() -> {
            serverState.setCurrentServerSpan(currentSpan);
            command.run();
        });
    };
}

From source file:com.google.cloud.trace.zipkin.autoconfigure.ZipkinStackdriverStorageAutoConfiguration.java

@Bean(name = "stackdriverExecutor")
@ConditionalOnMissingBean(Executor.class)
Executor executor() {/*from w w  w .  j a  v a2  s .  c  om*/
    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.axel.config.ServiceConfig.java

@Override
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    // to customize with your requirements
    executor.setCorePoolSize(5);/*from w  w  w . ja  v a2 s  .  co m*/
    executor.setMaxPoolSize(40);
    executor.setQueueCapacity(100);
    executor.setThreadNamePrefix("MyExecutor-");
    executor.initialize();
    return executor;
}

From source file:org.tocode.poc.service.config.ServiceConfig.java

@Override
public Executor getAsyncExecutor() {

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(20);/*from www . j  a v  a2 s  . co  m*/
    executor.setMaxPoolSize(50);
    executor.setQueueCapacity(500);
    executor.setThreadNamePrefix("Service-Thread");
    executor.initialize();
    return executor;
}

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

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

From source file:org.obiba.mica.config.AsyncConfiguration.java

@Bean(name = "opalExecutor")
public Executor getOpalAsyncExecutor() {
    log.debug("Creating Async Task Executor");

    Integer poolSize = propertyResolver.getProperty("opal.poolSize", Integer.class, DEFAULT_POOL_SIZE);

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(poolSize);/*from   w  w w  .ja v a  2  s.com*/
    executor.setMaxPoolSize(poolSize);
    executor.setQueueCapacity(
            propertyResolver.getProperty("opal.queueCapacity", Integer.class, DEFAULT_QUEUE_CAPACITY));
    executor.setThreadNamePrefix("mica-opal-executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}