Example usage for org.springframework.scheduling TaskScheduler scheduleWithFixedDelay

List of usage examples for org.springframework.scheduling TaskScheduler scheduleWithFixedDelay

Introduction

In this page you can find the example usage for org.springframework.scheduling TaskScheduler scheduleWithFixedDelay.

Prototype

ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay);

Source Link

Document

Schedule the given Runnable , starting as soon as possible and invoking it with the given delay between the completion of one execution and the start of the next.

Usage

From source file:com.netflix.genie.web.rpc.grpc.services.impl.v4.GRpcJobFileSyncServiceImpl.java

/**
 * Constructor.//from   w  w  w  . jav a2 s.  co  m
 *
 * @param jobFileSyncProperties The properties that configure how the sync server behaves
 * @param jobFileService        The log service to use to interact with the server side job directory
 * @param taskScheduler         The task scheduler to use
 */
public GRpcJobFileSyncServiceImpl(final JobFileSyncRpcProperties jobFileSyncProperties,
        final JobFileService jobFileService, final TaskScheduler taskScheduler) {
    this.jobFileSyncRpcProperties = jobFileSyncProperties;
    this.jobFileService = jobFileService;

    this.ackFuture = taskScheduler.scheduleWithFixedDelay(this::executeObserverAcknowledgements,
            this.jobFileSyncRpcProperties.getAckIntervalMilliseconds());
}

From source file:com.netflix.genie.web.services.loadbalancers.script.ScriptLoadBalancer.java

/**
 * Constructor./*  w ww .  j av  a 2s . c om*/
 *
 * @param asyncTaskExecutor   The asynchronous task executor to use to run the load balancer script in
 * @param taskScheduler       The task scheduler to schedule the script refresh task with
 * @param fileTransferService The file transfer service to use to download the script
 * @param environment         The program environment to get properties from
 * @param mapper              The object mapper to use to serialize objects to JSON for binding with scripts
 * @param registry            The metrics registry to use for collecting metrics
 */
public ScriptLoadBalancer(final AsyncTaskExecutor asyncTaskExecutor, final TaskScheduler taskScheduler,
        final GenieFileTransferService fileTransferService, final Environment environment,
        final ObjectMapper mapper, final MeterRegistry registry) {
    this.asyncTaskExecutor = asyncTaskExecutor;
    this.fileTransferService = fileTransferService;
    this.environment = environment;
    this.mapper = mapper;
    this.registry = registry;

    // Schedule the task to run with the configured refresh rate
    // Task will be stopped when the system stops
    final long refreshRate = this.environment.getProperty(ScriptLoadBalancerProperties.REFRESH_RATE_PROPERTY,
            Long.class, 300_000L);
    taskScheduler.scheduleWithFixedDelay(this::refresh, refreshRate);
}