4 (30.11.2022 3m) Flashcards

1
Q

What is JobFactory? Tell how default JobFactory works. Can you create own job factory and why you may need it?

A

When a trigger fires, the JobDetail (instance definition) it is associated with is loaded, and the job class it refers to (IJob) is instantiated via the JobFactory configured on the Scheduler.

The default JobFactory simply calls the default constructor of the job class using Activator.CreateInstance, then attempts to call setter properties on the class that match the names of keys within the JobDataMap.

You may want to create your own implementation of JobFactory to accomplish things such as having your application’s IoC or DI container produce/initialize the job instance.

scheduler.JobFactory = new YourJobFactory()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe DisallowConcurrentExecution attribute.

A

It is an attribute that can be added to the Job class that tells Quartz not to execute multiple instances of a job concurrently. Despite being added on IJob, real concurrency check is performed against IJobDetail.

For example you have a job SalesReportJob: IJob. And you created two IJobDetails upon it, “SalesReportJobForJoe” and “SalesReportJobForMike”. If “SalesReportJob” has this attribute, then only one instance of “SalesReportForJoe” can execute at a given time, but it can execute concurrently with an instance of “SalesReportForMike”. The constraint is based upon JobDetail, not on instances of the job class. However, it was decided (during the design of Quartz) to have the attribute carried on the class itself because it does often make a difference in how the class is coded.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe PersistJobDataAfterExecution attribute.

A

It is an attribute that can be added to the Job class that tells Quartz to update the stored copy of the JobDetail’s JobDataMap after the Execute() method completes successfully (without throwing an exception), such that the next execution of the same job (JobDetail) receives the updated values rather than the originally stored values.

Like the [DisallowConcurrentExecution] attribute, this applies to IJobDetail, not a IJob instance, though it was decided to have the job class carry the attribute because it does often make a difference to how the class is coded (e.g. the ‘statefulness’ will need to be explicitly ‘understood’ by the code within the execute method).

If you use the PersistJobDataAfterExecution attribute, you should strongly consider also using the [DisallowConcurrentExecution] attribute, in order to avoid possible confusion (race conditions) regarding what data was left stored when two instances of the same job (JobDetail) were executed concurrently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Descibe IJobDetail Durability setting.

A

Set by bool Durable property.

If a job is non-durable, it is automatically deleted from the scheduler once there are no longer any active triggers associated with it. In other words, non-durable jobs have a life span bounded by the existence of their triggers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Descibe IJobDetail RequestsRecovery setting.

A

Set by bool RequestsRecovery property.

If a job “requests recovery”, and it is executing during the time of a ‘hard shutdown’ of the scheduler (i.e. the process it is running within crashes or the machine is shut off), then it is re-executed when the scheduler is started again. In this case, the JobExecutionContext.Recovering property will return true.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly