Search in sources :

Example 36 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project codekvast by crispab.

the class SchedulingConfig method taskScheduler.

@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(5);
    return scheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 37 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project elastest-torm by elastest.

the class StompTestUtils method connectToRabbitMQ.

public static StompSession connectToRabbitMQ(int serverPort) throws InterruptedException, ExecutionException, TimeoutException {
    WebSocketContainer cont = ContainerProvider.getWebSocketContainer();
    cont.setDefaultMaxTextMessageBufferSize(65500);
    WebSocketClient webSocketClient = new StandardWebSocketClient(cont);
    WebSocketStompClient stompClient = new WebSocketStompClient(webSocketClient);
    stompClient.setMessageConverter(new StringMessageConverter());
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.initialize();
    // for heartbeats
    stompClient.setTaskScheduler(taskScheduler);
    stompClient.setDefaultHeartbeat(new long[] { 10000, 10000 });
    String url = "ws://localhost:" + serverPort + "/rabbitMq";
    StompSessionHandler sessionHandler = new LogConnectedSessionHandler();
    final int MAX_RETRIES = 5;
    int retry = 0;
    while (true) {
        try {
            StompSession stompSession = stompClient.connect(url, sessionHandler).get(10, TimeUnit.SECONDS);
            log.info("Test connected to RabbitMQ in URL '{}'", url);
            return stompSession;
        } catch (Exception e) {
            if (retry < MAX_RETRIES) {
                retry++;
                log.warn("Exception trying to connect to RabbitMQ: {}:{}", e.getClass().getName(), e.getMessage());
                log.info("Retrying {}/{} in 5 second", retry, MAX_RETRIES);
                Thread.sleep(5000);
            } else {
                throw e;
            }
        }
    }
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) WebSocketContainer(javax.websocket.WebSocketContainer) StompSession(org.springframework.messaging.simp.stomp.StompSession) StompSessionHandler(org.springframework.messaging.simp.stomp.StompSessionHandler) WebSocketStompClient(org.springframework.web.socket.messaging.WebSocketStompClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) StandardWebSocketClient(org.springframework.web.socket.client.standard.StandardWebSocketClient) WebSocketClient(org.springframework.web.socket.client.WebSocketClient) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)

Example 38 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project alien4cloud by alien4cloud.

the class SchedulingConfiguration method getPaaSScheduler.

@Bean(name = "paas-monitor-scheduler")
public Executor getPaaSScheduler() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(paasMonitorThreadPoolSize);
    threadPoolTaskScheduler.setThreadNamePrefix("paas-monitor-");
    return threadPoolTaskScheduler;
}
Also used : ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 39 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project cloudbreak by hortonworks.

the class AsyncConfig method taskScheduler.

@Bean
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler threadPoolTaskScheduler = new MDCCleanerThreadPoolTaskScheduler();
    threadPoolTaskScheduler.setPoolSize(TASK_SCHEDULER_POOL_SIZE);
    threadPoolTaskScheduler.setThreadNamePrefix("scheduledExecutor-");
    return threadPoolTaskScheduler;
}
Also used : MDCCleanerThreadPoolTaskScheduler(com.sequenceiq.cloudbreak.concurrent.MDCCleanerThreadPoolTaskScheduler) MDCCleanerThreadPoolTaskScheduler(com.sequenceiq.cloudbreak.concurrent.MDCCleanerThreadPoolTaskScheduler) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Bean(org.springframework.context.annotation.Bean)

Example 40 with ThreadPoolTaskScheduler

use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-boot-admin by codecentric.

the class RegistrationApplicationListenerTest method should_no_schedule_register_task_when_not_autoRegister.

@Test
public void should_no_schedule_register_task_when_not_autoRegister() {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.setAutoRegister(false);
    listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
    verify(scheduler, never()).scheduleAtFixedRate(isA(Runnable.class), eq(Duration.ofSeconds(10)));
}
Also used : ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) Test(org.junit.jupiter.api.Test)

Aggregations

ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)122 Test (org.junit.Test)41 Bean (org.springframework.context.annotation.Bean)32 BeanFactory (org.springframework.beans.factory.BeanFactory)31 Test (org.junit.jupiter.api.Test)26 CountDownLatch (java.util.concurrent.CountDownLatch)19 QueueChannel (org.springframework.integration.channel.QueueChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 ExecutorService (java.util.concurrent.ExecutorService)10 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 MqttPahoMessageDrivenChannelAdapter (org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 MqttPahoMessageHandler (org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler)6 JmsTemplate (org.springframework.jms.core.JmsTemplate)6 ArrayList (java.util.ArrayList)5 Log (org.apache.commons.logging.Log)5 MessageChannel (org.springframework.messaging.MessageChannel)5 File (java.io.File)4 ConnectionFactory (javax.jms.ConnectionFactory)4