Java offers a
ScheduledExecutorService that allows developers to create and schedule tasks.
A task is a class that implements ONE method to be executed that performs the desired duties. It is NOT necessary for the task itself to implement the
Runnable interface, although the tasks will be run as a
Thread.
An important thing to notice is that by default threads are NOT marked as
daemons, therefore it might be worth setting such flag according to your needs.
Another important thing to note, is that the scheduler will hold on to references to cancelled tasks, which might lead to memory leaks, so it might be preferable to
setRemoveOnCancelPolicy to true.