ScheduledExecutorService or ScheduledThreadPoolExecutor
Creating ScheduledThreadPoolExecutor Using Executors
you can also look this one
http://tutorials.jenkov.com/java-util-concurrent/scheduledexecutorservice.html
if you want to use it periodically, you should use this method
scheduleAtFixedRate (Runnable, long initialDelay, long period, TimeUnit timeunit)
ScheduledExecutorService
is an interface (a contract) and ScheduledThreadPoolExecutor
implements that interface.
Since you cannot directly instantiate an interface, you have to use implementation through instantiating ScheduledThreadPoolExecutor
directly or through means of factory method such as java.util.concurrent.Executors
that returns an instance of ScheduledThreadPoolExecutor
.
e.g
ScheduledExecutorService scheduler =
Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); //returns a ScheduledFuture
Have a look at Scheduled Executor Service Usage for Andriod
This is the same, ScheduledThreadPoolExecutor
is an implementation of ScheduledExecutorService