001package io.ebean; 002 003import java.util.concurrent.Callable; 004import java.util.concurrent.ScheduledExecutorService; 005import java.util.concurrent.ScheduledFuture; 006import java.util.concurrent.TimeUnit; 007 008/** 009 * Background thread pool service for executing of tasks asynchronously. 010 * <p> 011 * This service is used internally by Ebean for executing background tasks such 012 * as the {@link Query#findFutureList()} and also for executing background tasks 013 * periodically. 014 * </p> 015 * <p> 016 * This service has been made available so you can use it for your application 017 * code if you want. It can be useful for some server caching implementations 018 * (background population and trimming of the cache etc). 019 * </p> 020 * 021 * @author rbygrave 022 */ 023public interface BackgroundExecutor { 024 025 /** 026 * Execute a task in the background. 027 */ 028 void execute(Runnable r); 029 030 /** 031 * Execute a task periodically with a fixed delay between each execution. 032 * <p> 033 * For example, execute a runnable every minute. 034 * <p> 035 * The delay is the time between executions no matter how long the task took. 036 * That is, this method has the same behaviour characteristics as 037 * {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)} 038 */ 039 void executePeriodically(Runnable r, long delay, TimeUnit unit); 040 041 /** 042 * Execute a task periodically additionally with an initial delay different from delay. 043 */ 044 void executePeriodically(Runnable r, long initialDelay, long delay, TimeUnit unit); 045 046 /** 047 * Schedules a Runnable for one-shot action that becomes enabled after the given delay. 048 * 049 * @return a ScheduledFuture representing pending completion of the task and 050 * whose get() method will return null upon completion 051 */ 052 ScheduledFuture<?> schedule(Runnable r, long delay, TimeUnit unit); 053 054 /** 055 * Schedules a Callable for one-shot action that becomes enabled after the given delay. 056 * 057 * @return a ScheduledFuture that can be used to extract result or cancel 058 */ 059 <V> ScheduledFuture<V> schedule(Callable<V> c, long delay, TimeUnit unit); 060 061 062}