Quartz.net scheduler using clustering

I am using the clustering option and I have some problems with it:

  • When I use with two machines the jobs that I created are started at first without connecting to their definition. for example: if I define a task to run after ten seconds, it can run every two seconds at the beginning and only from the 2nd run it correctly - every ten seconds.

  • Two machines do the same job in one minute (but not in the same millisecond) and run the job twice, I tried to use the lock handler property, but maybe I didn't define it well ..

This is my code:

NameValueCollection properties = new NameValueCollection();

properties["quartz.scheduler.instanceName"] = "TestSchedulerNECH";
properties["quartz.scheduler.instanceId"] = "instance_one";
properties["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz";
properties["quartz.threadPool.threadCount"] = "200";
properties["quartz.threadPool.threadPriority"] = "Normal";
properties["quartz.jobStore.misfireThreshold"] = "60000";
properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
properties["quartz.jobStore.useProperties"] = "false";
properties["quartz.jobStore.dataSource"] = "default";
properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
properties["quartz.jobStore.clustered"] = "true";
properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";
properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz";
properties["quartz.dataSource.default.connectionString"] = "Server=localhost;Database=mydb;Trusted_Connection=False;User=admin;Password=123456";
properties["quartz.dataSource.default.provider"] = "SqlServer-20";


ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();

string schedId = sched.SchedulerInstanceId;

for (int i = 1; i <= 5; i++)
{

IJobDetail job = JobBuilder.Create<SimpleRecoveryJob>()
    .WithIdentity("job_" + i, schedId)
    .RequestRecovery(false)
    .Build();

ITrigger trigger = TriggerBuilder.Create()
    .StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second))
    .WithCronSchedule("0/10 * * * * ? *")
    .ForJob(job)
    .EndAt(DateBuilder.FutureDate(3, IntervalUnit.Minute))
    .Build();

sched.ScheduleJob(job, trigger);
}

sched.Start();

      

Can anyone help me?

+3


source to share


1 answer


I know this is an old thread, but if we want to disallow concurrent execution, we must add the DisallowConcurrentExecution attribute to the job class.



+1


source







All Articles