001package com.avaje.ebean;
002
003import java.util.concurrent.ScheduledExecutorService;
004import java.util.concurrent.TimeUnit;
005
006/**
007 * Background thread pool service for executing of tasks asynchronously.
008 * <p>
009 * This service is used internally by Ebean for executing background tasks such
010 * as the {@link Query#findFutureList()} and also for executing background tasks
011 * periodically.
012 * </p>
013 * <p>
014 * This service has been made available so you can use it for your application
015 * code if you want. It can be useful for some server caching implementations
016 * (background population and trimming of the cache etc).
017 * </p>
018 * 
019 * @author rbygrave
020 */
021public interface BackgroundExecutor {
022
023  /**
024   * Execute a task in the background.
025   */
026  void execute(Runnable r);
027
028  /**
029   * Execute a task periodically with a fixed delay between each execution.
030   * <p>
031   * For example, execute a runnable every minute.
032   * </p>
033   * <p>
034   * The delay is the time between executions no matter how long the task took.
035   * That is, this method has the same behaviour characteristics as
036   * {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)}
037   * </p>
038   */
039  void executePeriodically(Runnable r, long delay, TimeUnit unit);
040}