Package org.springframework.scheduling.concurrent

Examples of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor


    factory.setBeanName("stepName");
    factory.setTransactionManager(transactionManager);
    factory.setJobRepository(repository);
    factory.setCommitInterval(3);
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(3);
    taskExecutor.setMaxPoolSize(6);
    taskExecutor.setQueueCapacity(0);
    taskExecutor.afterPropertiesSet();
    factory.setTaskExecutor(taskExecutor);
   
    JdbcTestUtils.deleteFromTables(new JdbcTemplate(dataSource), "ERROR_LOG");

  }
View Full Code Here


    }


    @Bean
    public ThreadPoolTaskExecutor taskExecutor() {
        return new ThreadPoolTaskExecutor() {{
            setCorePoolSize(15);
            setMaxPoolSize(25);
            setQueueCapacity(50);
            setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
        }};
View Full Code Here

  }

  @Test
  public void testMultithreadedSkipInWriter() throws Throwable {

    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(3);
    taskExecutor.setMaxPoolSize(6);
    taskExecutor.setQueueCapacity(0);
    taskExecutor.afterPropertiesSet();
    factory.setTaskExecutor(taskExecutor);

    @SuppressWarnings("unchecked")
    Map<Class<? extends Throwable>, Boolean> skippable = getExceptionMap(Exception.class);
    factory.setSkippableExceptionClasses(skippable);
View Full Code Here

  @Test
  public void testThrottleLimitEarlyFinishThreadStarvation() throws Exception {

    early = 2;
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    // Set the concurrency limit below the throttle limit for possible
    // starvation condition
    taskExecutor.setMaxPoolSize(20);
    taskExecutor.setCorePoolSize(10);
    taskExecutor.setQueueCapacity(0);
    // This is the most sensible setting, otherwise the bookkeeping in
    // ResultHolderResultQueue gets out of whack when tasks are aborted.
    taskExecutor
        .setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    taskExecutor.afterPropertiesSet();
    template.setTaskExecutor(taskExecutor);

    template.iterate(callback);
    int frequency = Collections.frequency(items, "null");
    // System.err.println("Frequency: " + frequency);
    // System.err.println("Items: " + items);
    // Extra tasks will be submitted before the termination is detected
    assertEquals(total, items.size() - frequency);
    assertTrue(frequency <= throttleLimit + 1);

    taskExecutor.destroy();

  }
View Full Code Here

        int total = 10000;
        final int group = total / 20;
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(total);

        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.afterPropertiesSet();
        for (int i = 0; i < 20; i++) {
            final int threadCount = i;
            executor.execute(new Runnable() {
                public void run() {
                    int start = threadCount * group;
                    for (int i = 0; i < group; i++) {
                        try {
                            // do some random sleep to simulate spread in user activity
View Full Code Here

    }

    @Bean
    @ConditionalOnMissingBean(name = "metricsExecutor")
    public Executor metricsExecutor() {
      ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
      return executor;
    }
View Full Code Here

    }

    @Override
    public Executor getAsyncExecutor() {
        log.debug("Creating Async Task Executor");
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(2);
        executor.setMaxPoolSize(50);
        executor.setQueueCapacity(10000);
        executor.setThreadNamePrefix("TatamiExecutor-");
        executor.initialize();
        return executor;
    }
View Full Code Here

  public void defaultExecutor() throws Exception {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
        MetricRepositoryAutoConfiguration.class);
    ExecutorSubscribableChannel channel = context
        .getBean(ExecutorSubscribableChannel.class);
    ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) channel.getExecutor();
    context.close();
    assertTrue(executor.getThreadPoolExecutor().isShutdown());
  }
View Full Code Here

            throws BeansException {

        if (applicationContext instanceof WebApplicationContext) {
            WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext;
            if (ThreadPoolTaskExecutor.class == bean.getClass()) {
                ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean;
                String paramCorePoolSize = webApplicationContext.getServletContext()
                        .getInitParameter(PORTAL_EXECUTOR_CORE_POOL_SIZE);
                if (StringUtils.isNotBlank(paramCorePoolSize)) {
                    if (logger.isInfoEnabled()) {
                        logger.info("found param " + PORTAL_EXECUTOR_CORE_POOL_SIZE + "="
                                + paramCorePoolSize);
                    }
                    executor.setCorePoolSize(Integer.parseInt(paramCorePoolSize));
                } else {
                    throw new IllegalArgumentException(
                            "please add '<context-param><param-name>portalExecutorCorePoolSize</param-name><param-value>a number here</param-value></context-param>' in your web.xml");
                }
                String paramMaxPoolSize = webApplicationContext.getServletContext()
                        .getInitParameter(PORTAL_EXECUTOR_MAX_POOL_SIZE);
                if (StringUtils.isNotBlank(paramMaxPoolSize)) {
                    if (logger.isInfoEnabled()) {
                        logger.info("found param " + PORTAL_EXECUTOR_MAX_POOL_SIZE + "="
                                + paramMaxPoolSize);
                    }
                    executor.setMaxPoolSize(Integer.parseInt(paramMaxPoolSize));
                }
                String paramKeepAliveSeconds = webApplicationContext.getServletContext()
                        .getInitParameter(PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS);
                if (StringUtils.isNotBlank(paramKeepAliveSeconds)) {
                    if (logger.isInfoEnabled()) {
                        logger.info("found param " + PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS + "="
                                + paramKeepAliveSeconds);
                    }
                    executor.setKeepAliveSeconds(Integer.parseInt(paramKeepAliveSeconds));
                }
            } else if (List.class.isInstance(bean) && "portalListenerList".equals(beanName)) {
                String paramListeners = webApplicationContext.getServletContext().getInitParameter(
                        PORTAL_LISTENERS);
                @SuppressWarnings("unchecked")
View Full Code Here

    System.out.println("file poller isRunning before start: " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("filePoller.start()").build());
    System.out.println("file poller isRunning after start:  " + filePoller.isRunning());
    controlChannel.send(MessageBuilder.withPayload("filePoller.stop()").build());
    System.out.println("file poller isRunning after stop:   " + filePoller.isRunning());
    ThreadPoolTaskExecutor executor = context.getBean("myExecutor", ThreadPoolTaskExecutor.class);
    System.out.println("max pool size before update: " + executor.getMaxPoolSize());
    controlChannel.send(MessageBuilder.withPayload("myExecutor.setMaxPoolSize(25)").build());
    System.out.println("max pool size after update:  " + executor.getMaxPoolSize());
  }
View Full Code Here

TOP

Related Classes of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.