Example usage for org.springframework.core.task SimpleAsyncTaskExecutor setConcurrencyLimit

List of usage examples for org.springframework.core.task SimpleAsyncTaskExecutor setConcurrencyLimit

Introduction

In this page you can find the example usage for org.springframework.core.task SimpleAsyncTaskExecutor setConcurrencyLimit.

Prototype

public void setConcurrencyLimit(int concurrencyLimit) 

Source Link

Document

Set the maximum number of parallel accesses allowed.

Usage

From source file:de.langmi.spring.batch.examples.complex.crosscutting.autothreadconf.AsyncTaskExecutorFactory.java

public static SimpleAsyncTaskExecutor createInstance() {
    SimpleAsyncTaskExecutor instance = new SimpleAsyncTaskExecutor();

    // set concurrencyLimit according to available processors
    Runtime runtime = Runtime.getRuntime();
    int nrCpu = runtime.availableProcessors();
    instance.setConcurrencyLimit(nrCpu);

    LOG.info("TaskExecutor ConcurrencyLimit:" + String.valueOf(nrCpu));

    return instance;
}

From source file:uk.ac.kcl.batch.JobConfiguration.java

@Bean
@Qualifier("slaveTaskExecutor")
public TaskExecutor taskExecutor() {
    //        ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor();
    //        exec.setMaxPoolSize(Integer.parseInt(env.getProperty("concurrencyLimit")));
    SimpleAsyncTaskExecutor exec = new SimpleAsyncTaskExecutor();
    exec.setConcurrencyLimit(concurrencyLimit);
    return exec;/*from   w w  w . j a  va  2  s .c  o m*/
}

From source file:org.springframework.batch.core.step.tasklet.AsyncTaskletStepTests.java

private void setUp() throws Exception {

    step = new TaskletStep("stepName");

    ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager();
    step.setTransactionManager(transactionManager);

    RepeatTemplate chunkTemplate = new RepeatTemplate();
    chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
    step.setTasklet(new TestingChunkOrientedTasklet<String>(new ListItemReader<String>(items), itemProcessor,
            itemWriter, chunkTemplate));

    jobRepository = new JobRepositorySupport();
    step.setJobRepository(jobRepository);

    TaskExecutorRepeatTemplate template = new TaskExecutorRepeatTemplate();
    template.setThrottleLimit(throttleLimit);
    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setConcurrencyLimit(concurrencyLimit);
    template.setTaskExecutor(taskExecutor);
    step.setStepOperations(template);//from   ww w .j  a va2s .c o m

    step.registerStream(new ItemStreamSupport() {
        private int count = 0;

        @Override
        public void update(ExecutionContext executionContext) {
            super.update(executionContext);
            executionContext.putInt("counter", count++);
        }
    });

}

From source file:org.springframework.batch.repeat.support.TaskExecutorRepeatTemplateBulkAsynchronousTests.java

@Test
public void testThrottleLimitEarlyFinishOneThread() throws Exception {

    early = 4;/*from  ww  w . j  a  v a2s  . co  m*/
    SimpleAsyncTaskExecutor taskExecutor = new SimpleAsyncTaskExecutor();
    taskExecutor.setConcurrencyLimit(1);

    // This is kind of slow with only one thread, so reduce size:
    throttleLimit = 10;
    total = 20;

    template.setThrottleLimit(throttleLimit);
    template.setTaskExecutor(taskExecutor);

    template.iterate(callback);
    int frequency = Collections.frequency(items, "null");
    // System.err.println("Frequency: " + frequency);
    // System.err.println("Items: " + items);
    assertEquals(total, items.size() - frequency);
    assertTrue(frequency <= throttleLimit + 1);

}