Search in sources :

Example 81 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project zipkin by openzipkin.

the class ZipkinMySQLStorageAutoConfiguration method executor.

@Bean
@ConditionalOnMissingBean(Executor.class)
Executor executor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("ZipkinMySQLStorage-");
    executor.initialize();
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 82 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.

the class DefaultJmsMessageListenerContainer method stop.

@Override
public void stop() throws JmsException {
    if (logger.isDebugEnabled()) {
        logger.debug("Stopping listenerContainer: " + this + " with cacheLevel: " + getCacheLevel() + " and sharedConnectionEnabled: " + sharedConnectionEnabled());
    }
    super.stop();
    if (taskExecutor instanceof ThreadPoolTaskExecutor) {
        ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) taskExecutor;
        executor.destroy();
    }
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 83 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project ocvn by devgateway.

the class AsyncConfiguration method getAsyncExecutor.

@Bean
@Override
public ThreadPoolTaskExecutor getAsyncExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(1);
    taskExecutor.setThreadNamePrefix("VNImportServiceExecutor-");
    return taskExecutor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 84 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project camel by apache.

the class JmsConcurrentConsumersTest method testConcurrentConsumersWithReply.

@Test
public void testConcurrentConsumersWithReply() throws Exception {
    // latch for the 5 exchanges we expect
    final CountDownLatch latch = new CountDownLatch(5);
    // setup a task executor to be able send the messages in parallel
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.afterPropertiesSet();
    for (int i = 0; i < 5; i++) {
        final int count = i;
        executor.execute(new Runnable() {

            public void run() {
                // request body is InOut pattern and thus we expect a reply (JMSReply)
                Object response = template.requestBody("activemq:a", "World #" + count);
                assertEquals("Bye World #" + count, response);
                latch.countDown();
            }
        });
    }
    long start = System.currentTimeMillis();
    // wait for test completion, timeout after 30 sec to let other unit test run to not wait forever
    assertTrue(latch.await(30000L, TimeUnit.MILLISECONDS));
    assertEquals("Latch should be zero", 0, latch.getCount());
    long delta = System.currentTimeMillis() - start;
    assertTrue("Should be faster than 20000 millis, took " + delta + " millis", delta < 20000L);
    executor.shutdown();
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 85 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project metacat by Netflix.

the class CommonServerConfig method taskExecutor.

/**
     * Get a task executor for executing tasks asynchronously that don't need to be scheduled at a recurring rate.
     *
     * @param metacatProperties The metacat properties to get number of executor threads from.
     *                          Likely best to do one more than number of CPUs
     * @return The task executor the system to use
     */
@Bean
public AsyncTaskExecutor taskExecutor(final MetacatProperties metacatProperties) {
    final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(metacatProperties.getEvent().getBus().getExecutor().getThread().getCount());
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)152 Bean (org.springframework.context.annotation.Bean)72 ExceptionHandlingAsyncTaskExecutor (io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor)19 Test (org.junit.jupiter.api.Test)19 BigInteger (java.math.BigInteger)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 RateLimiter (com.google.common.util.concurrent.RateLimiter)14 Test (org.junit.Test)14 Random (java.util.Random)12 ApplicationContext (org.springframework.context.ApplicationContext)12 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)9 Service (org.fisco.bcos.channel.client.Service)9 Credentials (org.fisco.bcos.web3j.crypto.Credentials)9 Web3j (org.fisco.bcos.web3j.protocol.Web3j)9 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)9 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 CountDownLatch (java.util.concurrent.CountDownLatch)8 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)6 MDCCleanerTaskDecorator (com.sequenceiq.cloudbreak.concurrent.MDCCleanerTaskDecorator)4