I would also recommend a ScheduledExecutorService , which provides increased flexibility regarding Timerand TimerTaskincluding the ability to configure the service using multiple threads. This means that if a specific task takes a long time to complete, it will not prevent other tasks from starting.
ScheduledExecutorService execService = Executors.newScheduledThreadPool(3);
execService.scheduleAtFixedRate(new Runnable() {
public void run() {
System.err.println("Hello, World");
}
}, 0L, 5L, TimeUnit.SECONDS);
source
share