Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I create a new quartz job and trigger or one job and many triggers?

I am looking to use quartz to schedule emails, but I'm not sure which approach to take:

  1. Create a new job and trigger whenever an email is scheduled OR
  2. Create a single job, and create a new trigger each time an email is scheduled

I need to pass the message/recipient etc either way, and I'm not sure whether creating heaps of jobs will start adding considerable memory overheads, as there will quite possibly be thousands of emails scheduled.

Update: These emails will be scheduled by users, not by me - so I will be adding these programmatically at runtime, they aren't scheduled to go out at any particular time.

like image 529
RodeoClown Avatar asked Nov 05 '08 02:11

RodeoClown


2 Answers

Quartz is intended to handle tens of thousands of triggers. The main limit to scalability here is the space available in your JobStore. A JDBCJobStore backed with a reasonable database should be able to handle hundreds of thousands of triggers.

If a single job can be parameterized through the trigger's job data map, create a single job and one trigger for each email. Quartz polls the job store periodically to look for triggers that are ready to fire. Quartz is designed to safely handle arbitrarily large result sets from this query.

What matters—and this really has nothing to do Quartz itself—is that you have the necessary bandwidth to execute peak loads. If users tend to schedule mails in clumps, you need to make sure that you have the computing resources to get the emails out. This would include network bandwidth, processing, and enough worker threads configured to utilize the available resources.

Note that you can configure what Quartz should do with a trigger if it does get too far behind in executing jobs. You can keep trying, skip the trigger, etc.

like image 56
erickson Avatar answered Nov 14 '22 22:11

erickson


Are the triggers to be based on a time schedule? You can use a CronTrigger to set up a more complex time based schedule rather than individual triggers.

like image 26
Feet Avatar answered Nov 14 '22 21:11

Feet