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

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

Introduction

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

Prototype

public ThreadPoolExecutor getThreadPoolExecutor() throws IllegalStateException 

Source Link

Document

Return the underlying ThreadPoolExecutor for native access.

Usage

From source file:com.github.liyp.rabbitmq.demo.Main.java

public static void main(String[] args) throws IOException, InterruptedException {
    // start spring context
    @SuppressWarnings({ "resource" })
    ApplicationContext context = new ClassPathXmlApplicationContext(
            "com/github/liyp/rabbitmq/demo/applicationContext.xml");

    RabbitTemplate rabbitTemplate = (RabbitTemplate) context.getBean("rabbitTemplate");
    for (int i = 0; i < 200; i++) {
        rabbitTemplate.convertAndSend("queue_one", "test queue 1 " + i);
        rabbitTemplate.convertAndSend("queue_two", new MsgBean("test queue 2 " + i));
    }/*from w w  w  . j a  va2 s  . c om*/
    Thread.sleep(5000);
    ThreadPoolTaskExecutor threadExe = (ThreadPoolTaskExecutor) context.getBean("taskExecutor");
    System.out.println(threadExe.getActiveCount());
    System.out.println(threadExe.getCorePoolSize());
    System.out.println(threadExe.getMaxPoolSize());
    System.out.println(threadExe.getPoolSize());
    System.out.println(threadExe.getThreadPoolExecutor().getCorePoolSize());

    // System.out.println("rsv: " +
    // rabbitTemplate.receiveAndConvert("queue_two"));
}

From source file:eu.artofcoding.beetlejuice.spring.SpringContextHelper.java

private void stopExecutors() {
    ThreadPoolTaskExecutor springTaskExecutor = applicationContext.getBean("taskExecutor",
            ThreadPoolTaskExecutor.class);
    ThreadPoolExecutor springExecutor = springTaskExecutor.getThreadPoolExecutor();
    springExecutor.shutdownNow();/* w ww.  j  a  va  2s  . co  m*/
    Map<String, ThreadPoolTaskExecutor> map = applicationContext.getBeansOfType(ThreadPoolTaskExecutor.class);
    ThreadPoolTaskExecutor t = null;
    for (String key : map.keySet()) {
        t = map.get(key);
        final ThreadPoolExecutor executor = t.getThreadPoolExecutor();
        executor.shutdownNow();
        logger.info(
                String.format("%s: active after shutdown: %d", executor.toString(), executor.getActiveCount()));
        logger.info(String.format("%s: completed after shutdown: %d", executor.toString(),
                executor.getCompletedTaskCount()));
    }
}

From source file:org.flockdata.helper.ExecutorHelper.java

public static Executor getExecutor(String name, String poolSize, int qCapacity) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    String vals[] = StringUtils.split(poolSize, "-");

    executor.setCorePoolSize(Integer.parseInt(vals[0]));
    if (vals.length == 2)
        executor.setMaxPoolSize(Integer.parseInt(vals[1]));
    else//  www .  ja  va2  s .c o m
        executor.setMaxPoolSize(Integer.parseInt(vals[0]));
    executor.setQueueCapacity(qCapacity);
    executor.setThreadNamePrefix(name + "-");
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();
    return executor.getThreadPoolExecutor();
}

From source file:org.springframework.integration.monitor.IntegrationMBeanExporter.java

@ManagedOperation
public void stopExecutors() {
    if (logger.isDebugEnabled()) {
        logger.debug("Stopping executors" + (this.shutdownForced ? "(force)" : ""));
    }//from   w w  w.  ja v  a 2  s . c o  m
    List<ExecutorService> executorServices = new ArrayList<ExecutorService>();
    Map<String, ThreadPoolTaskExecutor> executors = this.applicationContext
            .getBeansOfType(ThreadPoolTaskExecutor.class);
    for (Entry<String, ThreadPoolTaskExecutor> entry : executors.entrySet()) {
        ThreadPoolTaskExecutor executor = entry.getValue();
        if (executor == this.shutdownExecutor) {
            logger.debug("Skipping shutdown of shutdown executor");
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Stopping executor " + executor.getThreadNamePrefix());
            }
            ExecutorService executorService = executor.getThreadPoolExecutor();
            executorServices.add(executorService);
            doShutdownExecutorService(executorService);
        }
    }
    waitForExecutors(executorServices);
    logger.debug("Stopped executors");
}

From source file:org.springframework.web.socket.config.WebSocketMessageBrokerStats.java

public void setInboundChannelExecutor(ThreadPoolTaskExecutor inboundChannelExecutor) {
    this.inboundChannelExecutor = inboundChannelExecutor.getThreadPoolExecutor();
}

From source file:org.springframework.web.socket.config.WebSocketMessageBrokerStats.java

public void setOutboundChannelExecutor(ThreadPoolTaskExecutor outboundChannelExecutor) {
    this.outboundChannelExecutor = outboundChannelExecutor.getThreadPoolExecutor();
}