How does a quartz planner work?

My question is: how does the quartz scheduler work and how does it differ from the usual class that implements the Runnable interface (basically a thread), which wakes up according to a given time interval and does the required work?

Is this just a convenient way to do things (using the quartz scheduler), for example, specify the task configuration via XML files and easily add new tasks to the existing scheduler or is there something else for this? Moreover, I mean that he does some optimizations, such as he does not hang the thread for the entire duration and frees it? Is this a polling mechanism in which the thread continues to check the system time and sees if the specified period of time has passed or does it register with the system clock when the clock itself notifies the quartz scheduler?

Please let me know if any further clarification is required on the above issue.

+4
source share
1 answer

After posting the question, I looked at the content on the Internet and found useful information about the same. Sorry to post the question and answer it myself, but that would be helpful to anyone who might want to understand the same thing.

Here are the advantages of Quartz and its comparison with the regular Java timer interface:

  • Quartz is quite flexible and contains several usage paradigms that can be used separately or together to achieve the desired behavior and allow you to write your code in a way that seems most “natural” to your project.
  • Quartz is very lightweight and requires very little setup / configuration - it can actually be used out of the box if your needs are relatively simple.
  • Quartz is fault tolerant and can save (“remember”) scheduled tasks between system restarts.

On the other hand, it overcomes the following problems in the timer interface:

  • Timers do not have a save mechanism.
  • Timers have inflexible scheduling (only for setting the start and repeat times, nothing depends on dates, time of day, etc.).
  • Timers do not use a thread pool (one thread per timer)
  • Timers do not have real control schemes - you will have to write your own mechanism for remembering, organizing and searching for your tasks by name, etc.

If someone wants to add any information to the above, please feel free to.

+16
source

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


All Articles