As others have mentioned, no it is not deprecated but I personally always use ScheduledExecutorService
instead as it offers a richer API and more flexibility:
ScheduledExecutorService
allows you to specify the number of threads whereasTimer
always uses a single thread.ScheduledExecutorService
can be constructed with aThreadFactory
allowing control over thread aspects other than the name / daemon status (e.g. priority,ThreadGroup
,UncaughtExceptionHandler
).ScheduledExecutorService
allows tasks to be scheduled with fixed delay as well as at a fixed rate.ScheduledExecutorService
acceptsCallable
/Runnable
as it’s unit of work, meaning that you don’t need to subclassTimerTask
specifically to use it; i.e. you could submit the sameCallable
implementation to a regularExecutorService
or aScheduledExecutorService
.