In Java you have Many tools to schedule job to be executed in exact time in the future, here is a list of tools I have learned and used:

  • Open Symphony Quartz
  • EJB timer service
  • Java built-in Timer Task

If your are working in a web application that supports EJB 3.0 I strongly recommend using EJB timer service for the following:

  • Transaction support.
  • Persistency.
  • Repetitive executions.
  • No need for 3rd party implementations- the service provided by the EJB container
  • Ease of use.
  • Rich interfaces.

If your are working in standalone application with no container support I recommend Quartz for the following:

  • Using separate schema with support for many RBMS such mysql, oracle …etc.
  • Persistency.
  • Repetitive executions.
  • Rich interfaces.

Regarding using the Timer Task I’m not recommend using this utility at all in large scale web applications for the following:

  • Does not provide any persistency, so simply if your application terminated for any reason, all your task are gone.
  • It is not transactional.
  • This class does not offer real-time guarantees.
  • Internally, it uses a binary heap to represent its task queue, so the cost to schedule a task is O(log n), where n is the number of concurrently scheduled tasks.
  • Timer Task has a know low performance as it creates many threads to schedule your tasks.
  • If you schedule a task the current bean or caller class will still continue running in the memory because the created thread.