Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pros and cons of using java.util.timer vs Quartz for scheduling? [closed]

I've got to write an app that performs a series of tasks:

  1. task to be run once at 0200 hours every day.
  2. task to be run once at 0400 hours ever day
  3. task to be run at 15 minute intervals starting at 0003 hours
  4. task to be run at 15 minute intervals starting at 0005 hours

What are the pros and cons of using plain java.util.timer Vs. Quartz for this?

Are there any other alternatives I should be considering?

like image 694
Omar Kooheji Avatar asked Nov 10 '11 10:11

Omar Kooheji


3 Answers

For one, Quartz is more extendable. When you create a need for cron like jobs, quartz allready has the support for this. The threads that are used by your application are also managed by quartz, so you don't have to be starting your own thread. It is nice that this is handled by the Quartz Scheduler. It also integrates with the spring framework (don't know if that is applicable in your case). Quartz has reasonable documentation and is backed by a community.

Don't really know if the java.util.Timer is really used in Enterprise environments, but this depends on your application.

like image 40
jelle Avatar answered Sep 28 '22 05:09

jelle


Quartz

  • Additional dependency
  • API currently (late 2011) changing: 1.x on its way out, but the only one supported by Spring and possibly others
  • Jobs can be stored persistently; multiple Schedulers can be clustered for load balancing and failover
  • The differentiation between Job and Trigger takes a bit getting used to - but it is possible to
  • More powerful repeated scheduling expressions (e.g. CronTrigger for cron expressions)

Timer

  • Comes with JSE 1.3+ out of the box
  • For your functionality probably enough
  • Less flexible, but less complex as well

I am personally using Quartz + persistent storage for a Web application where triggers can be created interactively and should survive restarts, using Spring's scheduling abstraction. Both APIs IMHO lack an important concept: retrying failed tasks after a certain period of time. Adding this for myself was a pain for repeated tasks that should be retried as well.

like image 176
nd. Avatar answered Sep 28 '22 04:09

nd.


an update: now (in 2014) with the advent of inbuilt java schedulers in Java 1.6, 1.7,.... i think quartz is less of a choice.

like image 38
nabeel Avatar answered Sep 28 '22 03:09

nabeel