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

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

Introduction

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

Prototype

public void initialize() 

Source Link

Document

Set up the ExecutorService.

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);//from   www.j  av  a 2s  . c  om

    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);/*from  w  w w. j a  v  a 2 s.c o  m*/
    taskExecutor.setMaxPoolSize(4);
    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);//w  ww .ja  v  a  2s .  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 BasicGeneticAlgorithm();
    geneticAlgorithm.setPopulation(population);
    geneticAlgorithm.setStrategy(geneticAlgorithmStrategy);

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

From source file:zipkin.autoconfigure.storage.mysql.ZipkinMySQLStorageAutoConfiguration.java

@Bean
@ConditionalOnMissingBean(Executor.class)
Executor executor() {/*from w  w w  .j  a v a2s.c om*/
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("ZipkinMySQLStorage-");
    executor.initialize();
    return executor;
}

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();
    return command -> {
        ServerSpan currentSpan = serverState.getCurrentServerSpan();
        executor.execute(() -> {/*from  w w  w .ja  va 2  s  . co m*/
            serverState.setCurrentServerSpan(currentSpan);
            command.run();
        });
    };
}

From source file:org.calrissian.mango.jms.stream.JmsFileTransferSupportTest.java

public void testFullCycle() throws Exception {
    try {//from ww w. j a v  a 2 s  .c  om
        URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {

            @Override
            public URLStreamHandler createURLStreamHandler(String protocol) {
                if ("testprot".equals(protocol))
                    return new URLStreamHandler() {

                        @Override
                        protected URLConnection openConnection(URL u) throws IOException {
                            return new URLConnection(u) {

                                @Override
                                public void connect() throws IOException {

                                }

                                @Override
                                public InputStream getInputStream() throws IOException {
                                    return new ByteArrayInputStream(TEST_STR.getBytes());
                                }

                                @Override
                                public String getContentType() {
                                    return "content/notnull";
                                }
                            };
                        }
                    };
                return null;
            }
        });
    } catch (Error ignored) {
    }

    final ActiveMQTopic ft = new ActiveMQTopic("testFileTransfer");

    ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
    te.initialize();

    JmsFileSenderListener listener = new JmsFileSenderListener();
    final String hashAlgorithm = "MD5";
    listener.setHashAlgorithm(hashAlgorithm);
    listener.setStreamRequestDestination(ft);
    listener.setPieceSize(9);
    listener.setTaskExecutor(te);

    ConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    cf = new SingleTopicConnectionFactory(cf, "test");
    JmsTemplate jmsTemplate = new JmsTemplate();
    jmsTemplate.setConnectionFactory(cf);
    jmsTemplate.setReceiveTimeout(60000);
    listener.setJmsTemplate(jmsTemplate);

    Connection conn = cf.createConnection();
    conn.start();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = sess.createConsumer(ft);
    consumer.setMessageListener(listener);

    JmsFileReceiver receiver = new JmsFileReceiver();
    receiver.setHashAlgorithm(hashAlgorithm);
    receiver.setStreamRequestDestination(ft);
    receiver.setJmsTemplate(jmsTemplate);
    receiver.setPieceSize(9);

    JmsFileReceiverInputStream stream = (JmsFileReceiverInputStream) receiver.receiveStream("testprot:test");
    StringBuilder buffer = new StringBuilder();
    int read;
    while ((read = stream.read()) >= 0) {
        buffer.append((char) read);
    }
    stream.close();

    assertEquals(TEST_STR, buffer.toString());

    conn.stop();

}

From source file:org.kew.rmf.reconciliation.config.MvcConfig.java

/**
 * TaskExecutor for asynchronous pooled tasks
 *///w  ww. j  a v a2  s . com
@Bean
public TaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(2);
    taskExecutor.setMaxPoolSize(2);
    taskExecutor.initialize();
    return taskExecutor;
}

From source file:com.github.javarch.support.config.TaskConfig.java

/**.
 *///  w w w.j av  a  2  s.  c om
@Bean
public Executor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(7);
    executor.setMaxPoolSize(42);
    executor.setQueueCapacity(11);
    executor.setThreadNamePrefix("Executor-");
    executor.initialize();
    return executor;
}

From source file:net.brainage.nest.NestApplication.java

@Bean
public AsyncTaskExecutor asyncTaskExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(5);// w w w  .j av a 2s.c o  m
    taskExecutor.setMaxPoolSize(200);
    taskExecutor.setQueueCapacity(100);
    taskExecutor.setThreadNamePrefix("async-task-executor-");
    taskExecutor.initialize();
    return taskExecutor;
}

From source file:ch.javaee.basicMvc.config.SchedulingConfig.java

@Override
public Executor getAsyncExecutor() {
    logger.debug("Enter: getAsynchExecutor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(7);//from   w  w w  .  ja  v  a  2s. c  o  m
    executor.setMaxPoolSize(42);
    executor.setQueueCapacity(11);
    executor.setThreadNamePrefix("AsyncExecutor-");
    executor.initialize();
    logger.debug("Exit: getAsynchExecutor");
    return executor;
}