Search in sources :

Example 1 with ThreadPoolTaskExecutor

use of org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor in project opennms by OpenNMS.

the class CollectionCommanderStarter method start.

public void start() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(4);
    taskExecutor.initialize();
    taskExecutor.setMaxPoolSize(4);
    taskExecutor.setQueueCapacity(8);
    taskExecutor.initialize();
    Long startTime = System.currentTimeMillis();
    Integer i = 0;
    while (i < 100) {
        CollectionTask ct = new CollectionTask(1200, "SNMP_All_Metrics");
        PooledJobPublisher jobPublisher = new PooledJobPublisher(ct);
        taskExecutor.execute(jobPublisher);
        i++;
    }
    logger.info("All started '{}'ms", System.currentTimeMillis() - startTime);
    Boolean done = false;
    while (!done) {
        if (taskExecutor.getActiveCount() == 0) {
            logger.info("Tasks active '{}'", taskExecutor.getActiveCount());
            logger.info("All done '{}'ms", System.currentTimeMillis() - startTime);
            taskExecutor.shutdown();
            done = true;
        } else {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                logger.error("'{}'", e.getMessage());
            }
        }
    }
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) CollectionTask(org.opennms.nrtg.api.model.CollectionTask)

Example 2 with ThreadPoolTaskExecutor

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

the class AbstractMessageBrokerConfiguration method brokerChannelExecutor.

@Bean
public ThreadPoolTaskExecutor brokerChannelExecutor() {
    ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration();
    ThreadPoolTaskExecutor executor;
    if (reg.hasTaskExecutor()) {
        executor = reg.taskExecutor().getTaskExecutor();
    } else {
        // Should never be used
        executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(0);
        executor.setMaxPoolSize(1);
        executor.setQueueCapacity(0);
    }
    executor.setThreadNamePrefix("brokerChannel-");
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Bean(org.springframework.context.annotation.Bean)

Example 3 with ThreadPoolTaskExecutor

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

the class TaskExecutorRegistration method getTaskExecutor.

protected ThreadPoolTaskExecutor getTaskExecutor() {
    ThreadPoolTaskExecutor executor = (this.taskExecutor != null ? this.taskExecutor : new ThreadPoolTaskExecutor());
    executor.setCorePoolSize(this.corePoolSize);
    executor.setMaxPoolSize(this.maxPoolSize);
    executor.setKeepAliveSeconds(this.keepAliveSeconds);
    executor.setQueueCapacity(this.queueCapacity);
    executor.setAllowCoreThreadTimeOut(true);
    return executor;
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)

Example 4 with ThreadPoolTaskExecutor

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

the class TraceZipkinMySQLStorageAutoConfiguration method executor.

@Bean
@ConditionalOnMissingBean(Executor.class)
public Executor executor(ServerSpanState serverState) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setThreadNamePrefix("MySQLStorage-");
    executor.initialize();
    return command -> {
        ServerSpan currentSpan = serverState.getCurrentServerSpan();
        executor.execute(() -> {
            serverState.setCurrentServerSpan(currentSpan);
            command.run();
        });
    };
}
Also used : ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ZipkinMySQLStorageProperties(zipkin.autoconfigure.storage.mysql.ZipkinMySQLStorageProperties) Executor(java.util.concurrent.Executor) Brave(com.github.kristofa.brave.Brave) ServerSpanState(com.github.kristofa.brave.ServerSpanState) Endpoint(com.twitter.zipkin.gen.Endpoint) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.jooq.tools.StringUtils) ServerSpan(com.github.kristofa.brave.ServerSpan) UnknownHostException(java.net.UnknownHostException) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) Configuration(org.springframework.context.annotation.Configuration) ExecuteContext(org.jooq.ExecuteContext) DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) Qualifier(org.springframework.beans.factory.annotation.Qualifier) SQL_QUERY(zipkin.TraceKeys.SQL_QUERY) ExecuteListenerProvider(org.jooq.ExecuteListenerProvider) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) ServerSpan(com.github.kristofa.brave.ServerSpan) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 5 with ThreadPoolTaskExecutor

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

the class XQueryURLBasedConcurrencyTest method testConcurrency.

@Test
public void testConcurrency() throws Exception {
    int total = 1000;
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);
    // 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 threadCount = i;
        executor.execute(new Runnable() {

            public void run() {
                int start = threadCount * 200;
                for (int i = 0; i < 200; i++) {
                    try {
                        // do some random sleep to simulate spread in user activity
                        Thread.sleep(new Random().nextInt(10));
                    } catch (InterruptedException e) {
                    // ignore
                    }
                    template.sendBody("direct:start", "<mail><subject>" + (start + i) + "</subject><body>Hello world!</body></mail>");
                }
            }
        });
    }
    mock.assertIsSatisfied();
    // must use bodyAs(String.class) to force DOM to be converted to String XML
    // for duplication detection
    mock.assertNoDuplicates(bodyAs(String.class));
    executor.shutdown();
}
Also used : Random(java.util.Random) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)150 Bean (org.springframework.context.annotation.Bean)70 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 MDCCleanerTaskDecorator (com.sequenceiq.cloudbreak.concurrent.MDCCleanerTaskDecorator)4 ArrayList (java.util.ArrayList)4