Here you can find the source of executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit)
Parameter | Description |
---|---|
r | : Runnable to be posted (get it from RunnableCreatorUtil ) |
delay | : time in 'unit' waited before first execution |
period | : period in 'unit' between 2 executions |
unit | : TimeUnit for delay & period |
public static ScheduledFuture<?> executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit)
//package com.java2s; //License from project: Creative Commons License import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; public class Main { private static ScheduledExecutorService timerExService = Executors.newScheduledThreadPool(7); /**// w w w. ja v a 2 s .c o m * Posts a Runnable to be executed periodically in its own {@link Thread}. * @param r : {@link Runnable} to be posted (get it from {@link RunnableCreatorUtil}) * @param delay : time in 'unit' waited before first execution * @param period : period in 'unit' between 2 executions * @param unit : {@link TimeUnit} for delay & period * @return A {@link ScheduledFuture} to be able to manage failures & cancels. */ public static ScheduledFuture<?> executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit) { return timerExService.scheduleAtFixedRate(r, delay, period, unit); } }