Waiting jobs

36 views
Skip to first unread message

Олександр Калиняк

unread,
Jun 9, 2017, 8:54:57 AM6/9/17
to Quartz.NET
Hi!

Under heavy load some jobs can not be executed.
Let me explain on simple example.

I have job which imitate long running computation:

[DisallowConcurrentExecution]
class DummyJob : IJob
{
public void Execute(IJobExecutionContext context)
{
System.Diagnostics.Trace.WriteLine("DummyJob '" + context.JobDetail.Key.Name + "' executed: " + DateTime.Now.ToString("G"));
Thread.Sleep(10000);
}
}

Max threads in ThreadPool equal 1.
I create two instances of job with 5 seconds interval.

var props = new NameValueCollection
{
{ "quartz.threadPool.threadCount", "1" }
};

ISchedulerFactory sf = new StdSchedulerFactory(props);
var scheduler = sf.GetScheduler();
scheduler.Start();

var job1 = JobBuilder.Create<DummyJob>().WithIdentity("job1", "general").Build();
var trigger1 =
    TriggerBuilder.Create()
        .WithIdentity("trigger1", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();
var job2 = JobBuilder.Create<DummyJob>().WithIdentity("job2", "general").Build();
var trigger2 =
    TriggerBuilder.Create()
        .WithIdentity("trigger2", "general")
        .StartNow()
        .WithSimpleSchedule(x => x.WithIntervalInSeconds(5).RepeatForever().WithMisfireHandlingInstructionFireNow())
        .Build();

scheduler.ScheduleJob(job1, trigger1);
scheduler.ScheduleJob(job2, trigger2);

Thread.Sleep(60000);

scheduler.Shutdown(true);


Here is output:

DummyJob 'job1' executed: 09.06.2017 11:21:13
DummyJob 'job2' executed: 09.06.2017 11:21:23
DummyJob 'job1' executed: 09.06.2017 11:21:33
DummyJob 'job1' executed: 09.06.2017 11:21:43
DummyJob 'job1' executed: 09.06.2017 11:21:53
DummyJob 'job1' executed: 09.06.2017 11:22:03


As we can see, job2 was fired only once. And it has no chance to be executed again after that.
That's wierd. I would like Quartz let every job to be executed.

Philip Shaffer

unread,
Jun 20, 2017, 10:19:11 AM6/20/17
to Quartz.NET
I am not sure that your statement that Job2 has no chance to run again is true in theory, but in practice you are probably right.
Remove your [DisallowConcurrentExecution] attribute, and you will probably see more occurrences of Job2.
Alter your inheritance so that Job1 and Job2 are different job classes and you might see more occurrences of both.
But ultimately, your 1 thread job pool is probably an artificial constraint one wouldn't normally see in production except in special situations.
Also, your job scheduling is identical on both jobs (same start time, same interval, same duration, same priority).  So each time the scheduler brings the jobs up for submission to your single-thread thread pool, it has no criteria that differ between the two jobs other than the order in which they were scheduled.  And in that scenario, it always goes with the first one scheduled.  I hit this same situation myself when I started playing with the Quartz engine last week.
Good luck.
Reply all
Reply to author
Forward
0 new messages