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

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

Introduction

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

Prototype

public boolean isOneTimeTask() 

Source Link

Document

Is this task only ever going to execute once?

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   w  w w  . j ava2 s  .  c  o m
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());
            }
        }
    }
}