Search in sources :

Example 26 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project tutorials by eugenp.

the class AsyncConfiguration method getAsyncExecutor.

@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("baeldung-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ExceptionHandlingAsyncTaskExecutor(io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 27 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project cetc by DiscoverForever.

the class AsyncConfiguration method getAsyncExecutor.

@Override
@Bean(name = "taskExecutor")
public Executor getAsyncExecutor() {
    log.debug("Creating Async Task Executor");
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(jHipsterProperties.getAsync().getCorePoolSize());
    executor.setMaxPoolSize(jHipsterProperties.getAsync().getMaxPoolSize());
    executor.setQueueCapacity(jHipsterProperties.getAsync().getQueueCapacity());
    executor.setThreadNamePrefix("cetc-Executor-");
    return new ExceptionHandlingAsyncTaskExecutor(executor);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ExceptionHandlingAsyncTaskExecutor(io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 28 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-integration by spring-projects.

the class CallerBlocksPolicyTests method test1.

@Test
public void test1() throws Exception {
    final ThreadPoolTaskExecutor te = new ThreadPoolTaskExecutor();
    te.setCorePoolSize(2);
    te.setMaxPoolSize(2);
    te.setQueueCapacity(1);
    te.setRejectedExecutionHandler(new CallerBlocksPolicy(10000));
    te.initialize();
    final AtomicReference<Throwable> e = new AtomicReference<Throwable>();
    final CountDownLatch latch = new CountDownLatch(3);
    te.execute(() -> {
        try {
            Runnable foo = new Runnable() {

                @Override
                public void run() {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        Thread.currentThread().interrupt();
                        throw new RuntimeException();
                    }
                    latch.countDown();
                }
            };
            te.execute(foo);
            // this one will be queued
            te.execute(foo);
            // this one will be blocked and successful later
            te.execute(foo);
        } catch (TaskRejectedException tre) {
            e.set(tre.getCause());
        }
    });
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertNull(e.get());
    te.destroy();
}
Also used : TaskRejectedException(org.springframework.core.task.TaskRejectedException) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 29 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project spring-integration by spring-projects.

the class TcpNioConnectionTests method compositeExecutor.

private CompositeExecutor compositeExecutor() {
    ThreadPoolTaskExecutor ioExec = new ThreadPoolTaskExecutor();
    ioExec.setCorePoolSize(2);
    ioExec.setMaxPoolSize(4);
    ioExec.setQueueCapacity(0);
    ioExec.setThreadNamePrefix("io-");
    ioExec.setRejectedExecutionHandler(new AbortPolicy());
    ioExec.initialize();
    ThreadPoolTaskExecutor assemblerExec = new ThreadPoolTaskExecutor();
    assemblerExec.setCorePoolSize(2);
    assemblerExec.setMaxPoolSize(5);
    assemblerExec.setQueueCapacity(0);
    assemblerExec.setThreadNamePrefix("assembler-");
    assemblerExec.setRejectedExecutionHandler(new AbortPolicy());
    assemblerExec.initialize();
    return new CompositeExecutor(ioExec, assemblerExec);
}
Also used : CompositeExecutor(org.springframework.integration.util.CompositeExecutor) AbortPolicy(java.util.concurrent.ThreadPoolExecutor.AbortPolicy) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 30 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project irida by phac-nml.

the class IridaApiServicesConfig method uploadExecutor.

/**
 * @return An Executor for handling uploads to Galaxy.
 */
@Bean
public Executor uploadExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(4);
    taskExecutor.setMaxPoolSize(8);
    taskExecutor.setQueueCapacity(16);
    taskExecutor.setThreadPriority(Thread.MIN_PRIORITY);
    return taskExecutor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)

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