Java Thread Executor Execute executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit)

Here you can find the source of executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit)

Description

Posts a Runnable to be executed periodically in its own Thread .

License

Creative Commons License

Parameter

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

Return

A to be able to manage failures & cancels.

Declaration

public static ScheduledFuture<?> executePeriodicallyInThread(Runnable r, int delay, int period, TimeUnit unit) 

Method Source Code

//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);
    }
}

Related

  1. executeFuture(Callable callable)
  2. executeInCachedPool(Runnable runnable)
  3. executeInThread(Runnable r)
  4. executeInThreadPool(Runnable runnable)
  5. executeParallel(final List> callables, final int maxThreadCount)
  6. ExecuteThreads(ArrayList threads, int nThreads)
  7. invokeAsync(Runnable runnable)
  8. invokeLater(Runnable runnable)
  9. invokeOnBackgroundThread(Runnable runnable)