Java tutorial
//package com.java2s; /** ___ _ _ _ ___ _ _ _ | __(_)_ _ _____ __ ____ _| | | | _ \_ _ ___| |_ ___ __| |_(_)___ _ _ | _|| | '_/ -_) V V / _` | | | | _/ '_/ _ \ _/ -_) _| _| / _ \ ' \ |_| |_|_| \___|\_/\_/\__,_|_|_| |_| |_| \___/\__\___\__|\__|_\___/_||_| Developed by: Riccardo B. < riccardo@cryptolab.net > License: GNU GPL v3 **/ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class Main { protected static ScheduledThreadPoolExecutor EXECUTOR = new ScheduledThreadPoolExecutor(2); public static void scheduleTaskAndRepeat(Runnable task, int initialDelay, int repeatEveryXMs) { EXECUTOR.scheduleAtFixedRate(task, initialDelay, repeatEveryXMs, TimeUnit.MILLISECONDS); } }