Example usage for org.springframework.scheduling.concurrent ScheduledExecutorTask getTimeUnit

List of usage examples for org.springframework.scheduling.concurrent ScheduledExecutorTask getTimeUnit

Introduction

In this page you can find the example usage for org.springframework.scheduling.concurrent ScheduledExecutorTask getTimeUnit.

Prototype

public TimeUnit getTimeUnit() 

Source Link

Document

Return the time unit for the delay and period values.

Usage

From source file:org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean.java

/**
 * Register the specified {@link ScheduledExecutorTask ScheduledExecutorTasks}
 * on the given {@link ScheduledExecutorService}.
 * @param tasks the specified ScheduledExecutorTasks (never empty)
 * @param executor the ScheduledExecutorService to register the tasks on.
 *///from www. j av  a 2s. c om
protected void registerTasks(ScheduledExecutorTask[] tasks, ScheduledExecutorService executor) {
    for (int i = 0; i < tasks.length; i++) {
        ScheduledExecutorTask task = tasks[i];
        Runnable runnable = getRunnableToSchedule(task);
        if (task.isOneTimeTask()) {
            executor.schedule(runnable, task.getDelay(), task.getTimeUnit());
        } else {
            if (task.isFixedRate()) {
                executor.scheduleAtFixedRate(runnable, task.getDelay(), task.getPeriod(), task.getTimeUnit());
            } else {
                executor.scheduleWithFixedDelay(runnable, task.getDelay(), task.getPeriod(),
                        task.getTimeUnit());
            }
        }
    }
}