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.ebayopensource.scc.track.TrackerClientTest.java

@Test
public void test() throws InterruptedException {
    AppConfiguration config = mock(AppConfiguration.class);
    when(config.getString("trackerClient.endpoint.host")).thenReturn("127.0.0.1");
    when(config.getInt("trackerClient.endpoint.port")).thenReturn(8080);
    when(config.getString("trackerClient.endpoint.path"))
            .thenReturn("/build-service/webapi/serviceCache/tracker");
    when(config.getBoolean("trackerClient.endpoint.isSecure")).thenReturn(false);
    when(config.getInt("trackerClient.request.interval")).thenReturn(10000);

    TrackerClient tc = new TrackerClient(config, Executors.newScheduledThreadPool(1));
    tc.start();//from   ww  w  .  j  ava 2 s .  co m
    Thread.sleep(1000);
}

From source file:org.apache.nifi.processors.email.TestListenSMTP.java

@Before
public void before() {
    this.executor = Executors.newScheduledThreadPool(2);
}

From source file:org.wso2.carbon.identity.application.authentication.framework.store.SessionCleanUpService.java

/**
 * @param initialDelay//w w  w  . ja  v a2 s .co  m
 * @param delayBetweenRuns
 */
public SessionCleanUpService(long initialDelay, long delayBetweenRuns) {
    this.initialDelay = initialDelay;
    this.delayBetweenRuns = delayBetweenRuns;
    this.scheduler = Executors.newScheduledThreadPool(NUM_THREADS);
}

From source file:org.wso2.carbon.identity.application.authentication.framework.store.OperationCleanUpService.java

/**
 * @param initialDelay/*from  w  w w .  j a v  a 2  s .  c om*/
 * @param delayBetweenRuns
 */
public OperationCleanUpService(long initialDelay, long delayBetweenRuns) {
    this.initialDelay = initialDelay;
    this.delayBetweenRuns = delayBetweenRuns;
    this.scheduler = Executors.newScheduledThreadPool(NUM_THREADS);
}

From source file:io.smartspaces.system.StandaloneSmartSpacesEnvironment.java

/**
 * Create a new {@link StandaloneSmartSpacesEnvironment}.
 *
 * @return the space environment//  w w  w . j  a v a 2  s.co m
 */
public static StandaloneSmartSpacesEnvironment newStandaloneSmartSpacesEnvironment() {
    StandaloneSmartSpacesEnvironment environment = new StandaloneSmartSpacesEnvironment();

    environment.systemConfiguration = SimpleConfiguration.newConfiguration();
    environment.executorService = Executors.newScheduledThreadPool(NUM_THREADS_IN_POOL);
    environment.log = new StandardExtendedLog("container", new Jdk14Logger("test.smartspaces"));
    environment.serviceRegistry = new StandardServiceRegistry(environment);
    environment.timeProvider = new SettableTimeProvider();
    environment.eventObservableRegistry = new StandardEventObservableRegistry(environment.log);
    environment.managedResources = new StandardManagedResources(environment.log);
    environment.managedTasks = new StandardManagedTasks(environment.executorService, environment.log);
    environment.managedScope = new StandardManagedScope(environment.managedResources, environment.managedTasks,
            environment.executorService);
    environment.managedResources.startupResources();

    return environment;
}

From source file:org.trendafilov.odesk.notifier.Main.java

public void startup() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
    executor.scheduleAtFixedRate(alertDeamon, 1, 1, TimeUnit.MINUTES);

    while (true) {
        executor.submit(newJobPooler);//from  w ww.j  ava2  s . c  o  m
        int randomDelay = 3 + (int) (Math.random() * 5);
        Logger.info(String.format("Sleeping for: [%s]", randomDelay));
        try {
            Thread.sleep(randomDelay * 1000 * 60);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.amazonaws.codepipeline.jobworker.JobWorkerDaemon.java

/**
 * Initializes the daemon with default settings:
 * Scheduled Thread Pool with pool size 1 to invoke job poller on a fixed rate.
 * (Default every 30 seconds)/*from w  ww .j  a  va 2  s .  c  o  m*/
 * Uses third party action configuration as a default.
 */
public JobWorkerDaemon() {
    this(Executors.newScheduledThreadPool(1), new CustomActionJobWorkerConfiguration());
}

From source file:com.pepaproch.gtswsdl.client.RateLimitTest.java

@Test
public void testCOnsumeSLotAsync() {
    RateLimit rate = new RateLimit(5, 10, ChronoUnit.SECONDS);
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);
    final AtomicInteger cc = new AtomicInteger(0);
    Instant start = Instant.now();
    final Instant[] end = new Instant[1];

    Runnable r = () -> {//ww w. java 2  s  . c om
        for (int i = 0; i < 21; i++) {
            addTask(cc, scheduler, rate, end);
        }
    };
    Runnable r1 = () -> {
        for (int i = 0; i < 9; i++) {
            addTask(cc, scheduler, rate, end);

        }
    };

    r1.run();
    r.run();

    try {

        scheduler.awaitTermination(5, TimeUnit.SECONDS);

    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println(Duration.between(start, end[0]).toMillis());
}

From source file:com.omade.monitor.ClientApplication.java

public static void newVersionCheck() {
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    executor.scheduleAtFixedRate(/*w w  w .  j a v a2 s.c o  m*/
            new DoTask(config.getProperty("server.url"), config.getProperty("server.port")), 0, 1,
            TimeUnit.SECONDS);
}

From source file:org.springframework.cloud.consul.binder.ConsulInboundMessageProducer.java

public ConsulInboundMessageProducer(EventService eventService) {
    this.eventService = eventService;
    this.scheduler = Executors.newScheduledThreadPool(1);
    this.eventsRunnable = new Runnable() {

        @Override//from   w ww .  java2  s . co m
        public void run() {
            getEvents();
        }
    };
}