0
votes

Quartz API provide a way in which i can create a Job and add it to scheduler for future use by doing something like

SchdularFactory.getSchedulerInstance().addJob(jobDetail, false); 

This provides me the flexibility to create jobs store them with the scheduler and use them in later stage. i am wondering is there any way i can create triggers and add them to scheduler to be used in future.

Not sure if this is valid requirement but if its not possible than all i have to do is to associate the Trigger with any given/existing Job

1

1 Answers

3
votes

In Quartz there is a one-to-many relationship between jobs and triggers, which is understandable: one job can be run by several different triggers but one trigger can only run a single job. If you need to run several jobs, create one composite job that runs these jobs manually.

Back to your question. Creating a job without associated triggers is a valid use-case: you have a piece of logic and later you will attach one or more triggers to execute it at different points in time.

The opposite situation is weird - you want to create a trigger that will run something at a given time, but you don't know yet what. I can't imagine use-case for that.

Note that you can create a trigger for future use (with next fire time far in the future), but it must have a job attached.

Finally, check out How-To: Storing a Job for Later Use in the official documentation.