Pros and cons of using java.util.timer vs Quartz for planning?

I need to write an application that performs a number of tasks:

  • the task should be performed once every 0200 hours every day.
  • a task that will run once every 0400 hours at any time
  • the task should be run at 15-minute intervals, starting at 0003 hours.
  • the task should be run at 15-minute intervals, starting at 0005 hours.

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

Are there any other alternatives that I should consider?

+6
source share
3 answers

Quartz

  • Additional dependency
  • The API is currently (late 2011) changing: 1.x on output, but the only one supported by Spring and possibly others
  • Work can be stored permanently; Multiple schedulers can be grouped for load balancing and disaster recovery.
  • The differentiation between Job and Trigger is a bit getting used to - but maybe
  • More powerful repetitive scheduling expressions (e.g. CronTrigger for cron expressions)

Timer

  • Comes with JSE 1.3+ out of the box
  • Enough for your functionality
  • Less flexible but less complex as well

I personally use Quartz + persistent storage for a web application where triggers can be created interactively and must survive reboots using Spring scheduling abstraction . Both IMHO APIs do not have an important concept: re-execution of unsuccessful tasks after a certain period of time. Adding this to me was a pain for repeated tasks, which should also be repeated.

+9
source

Firstly, Quartz is more extensible. When you create the need for cron, quartz allready has support for this. The themes used by your application are also managed by quartz, so you do not need to start your own thread. It's nice that this is handled by a quartz planner. It also integrates with the spring framework (I don't know if this applies in your case). Quartz has reasonable documentation and is maintained by the community.

I do not know if java.util.Timer is really used in corporate environments, but it depends on your application.

+1
source

update: now (in 2014) with the advent of built-in java schedulers in Java 1.6, 1.7, .... I think quartz is not a choice.

+1
source

Source: https://habr.com/ru/post/901200/


All Articles