Example usage for java.util.concurrent Executors newScheduledThreadPool

List of usage examples for java.util.concurrent Executors newScheduledThreadPool

Introduction

In this page you can find the example usage for java.util.concurrent Executors newScheduledThreadPool.

Prototype

public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) 

Source Link

Document

Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.

Usage

From source file:org.ros.internal.node.DefaultNodeTest.java

@Before
public void setUp() throws Exception {
    scheduledExecutorService = Executors.newScheduledThreadPool(Integer.MAX_VALUE);
    masterServer = new MasterServer(BindAddress.newPublic(), AdvertiseAddress.newPublic());
    masterServer.start();/* ww  w  . j ava2  s .  c  om*/
    masterUri = masterServer.getUri();
    checkHostName(masterUri.getHost());
    privateNodeConfiguration = NodeConfiguration.newPrivate(masterUri);
    privateNodeConfiguration.setNodeName("node_name");
    nodeFactory = new DefaultNodeFactory(scheduledExecutorService);
}

From source file:com.amazonaws.services.cloudtrail.processinglibrary.factory.ThreadPoolFactory.java

/**
 * Create an instance of ScheduledExecutorService. We only need single thread to poll messages
 * from the SQS queue./*from   w w  w  .  j a  v a 2  s  .  com*/
 *
 * @return ScheduledExecutorService continuous poll messages from SQS queue.
 */
public ScheduledExecutorService createScheduledThreadPool() {
    return Executors.newScheduledThreadPool(1);
}

From source file:org.cruxframework.crux.tools.codeserver.HotDeploymentScanner.java

/**
 * //from  www  . ja  v a  2 s. c  o  m
 * @param hostName
 * @param port
 * @param moduleToCompile
 * @param userAgent
 * @param locale
 * @param poolSize
 */
private HotDeploymentScanner(String hostName, int port, String moduleToCompile, String userAgent, String locale,
        int poolSize) {
    this.hostName = hostName;
    this.port = port;
    this.moduleToCompile = moduleToCompile;
    this.userAgent = userAgent;
    this.locale = locale;
    threadPool = Executors.newScheduledThreadPool(poolSize);
}

From source file:org.bremersee.common.spring.autoconfigure.SchedulingAutoConfiguration.java

@Bean
public Executor taskScheduler() {
    return Executors.newScheduledThreadPool(properties.getScheduledThreadPool());
}

From source file:org.mortbay.jetty.load.collector.CollectorClient.java

public CollectorClient start() throws Exception {

    // at least a default one
    if (this.collectorResultHandlers.isEmpty()) {
        this.collectorResultHandlers = Arrays.asList(new LoggerCollectorResultHandler());
    }//from  w  ww . j  a  v a2s  .  c  o m

    this.scheduledExecutorService = Executors.newScheduledThreadPool(addresses.size());

    for (String address : this.addresses) {
        this.scheduledExecutorService.scheduleWithFixedDelay(() -> {

            try {
                HttpClient httpClient = new HttpClient();
                httpClient.start();
                httpClients.add(httpClient);

                ObjectMapper objectMapper = new ObjectMapper();

                // response time per path informations
                ContentResponse contentResponse = httpClient //
                        .newRequest("http://" + address + "/collector/response-times") //
                        .send();

                LOGGER.debug("response time per path status: {}, response: {}", //
                        contentResponse.getStatus(), //
                        contentResponse.getContentAsString());

                TypeReference<Map<String, CollectorInformations>> typeRef = new TypeReference<Map<String, CollectorInformations>>() {
                };

                Map<String, CollectorInformations> responseTimePerPath = objectMapper
                        .readValue(contentResponse.getContentAsString(), typeRef);

                for (CollectorResultHandler collectorResultHandler : collectorResultHandlers) {
                    collectorResultHandler.handleResponseTime(responseTimePerPath);
                }

            } catch (Throwable e) {
                LOGGER.warn(e);
            }

        }, 1, this.scheduleDelayInMillis, TimeUnit.MILLISECONDS);
    }

    return this;
}

From source file:com.magnet.mmx.util.AlertEventsManagerTest.java

public void testInterEmailTime() {
    setupMocks();//from  ww  w  .j ava  2s .com
    long testDurationMinutes = 5;
    MMXConfiguration.getConfiguration().setValue(MMXConfigKeys.ALERT_EMAIL_ENABLED, "true");
    MMXConfiguration.getConfiguration().setValue(MMXConfigKeys.ALERT_INTER_EMAIL_TIME_MINUTES, "1");
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2);
    ScheduledFuture<?> future = executorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            AlertEventsManager.post(getRandomEvent());
        }
    }, 0L, 500, TimeUnit.MILLISECONDS);
    List<ScheduledFuture<?>> list = new ArrayList<ScheduledFuture<?>>();
    list.add(future);
    executorService.schedule(new StopTestTask(list), testDurationMinutes, TimeUnit.MINUTES);
    while (!future.isDone())
        ;
    LOGGER.trace("testInterEmailTime : average inter email time = {}", getAvg(elapsedTimes));
}

From source file:com.netflix.conductor.core.events.EventProcessor.java

@Inject
public EventProcessor(ExecutionService es, MetadataService ms, ActionProcessor ap, Configuration config,
        ObjectMapper om) {// w  w w .  j  a  va 2  s .c  o  m
    this.es = es;
    this.ms = ms;
    this.ap = ap;
    this.om = om;

    int executorThreadCount = config.getIntProperty("workflow.event.processor.thread.count", 2);
    if (executorThreadCount > 0) {
        this.executors = Executors.newFixedThreadPool(executorThreadCount);
        refresh();
        Executors.newScheduledThreadPool(1).scheduleAtFixedRate(() -> refresh(), 60, 60, TimeUnit.SECONDS);
    } else {
        logger.warn("Event processing is DISABLED.  executorThreadCount set to {}", executorThreadCount);
    }
}

From source file:com.barchart.http.handlers.TestCancellableRequestHandler.java

@Test
public void testCancellableRequest() throws Exception {

    final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

    final HttpGet get = new HttpGet("http://localhost:8888/client-disconnect");

    executor.schedule(new Runnable() {

        @Override/*  w  w  w  . j av  a2s  .com*/
        public void run() {
            System.out.println("Aborting " + get);
            get.abort();
        }

    }, 250, TimeUnit.MILLISECONDS);

    try {
        System.out.println("Executing " + get);
        client.execute(get);
    } catch (final Exception e) {
    }

    CallableTest.waitFor(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return clientDisconnect.lastFuture != null && clientDisconnect.lastFuture.isCancelled();
        }
    });

    assertNotNull(clientDisconnect.lastFuture);
    assertTrue(clientDisconnect.lastFuture.isCancelled());

}

From source file:org.libreoffice.impressremote.communication.CommunicationServiceWear.java

@Override
public void onDestroy() {
    Log.v(TAG, "onDestroy");
    if (null != googleApiClient) {
        notifyWearStop();/*  ww w  .j  a v  a2 s. co  m*/
        final ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
        exec.schedule(new Runnable() {
            @Override
            public void run() {
                if (googleApiClient != null) {
                    if (googleApiClient.isConnected()) {
                        googleApiClient.disconnect();
                        Log.v(TAG, "GoogleApiClient disconnected");
                    }
                }
            }
        }, 2, TimeUnit.SECONDS);
    }
    super.onDestroy();
}