Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz.net Scheduler using clustering

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

  1. When I using with two machines the jobs that I created runs in the beginning without connection to theirs definition. for example: if I defined the job to run once a ten second it can run every two second on the beginning and only from the 2th running it's correctly - every ten second.

  2. The two machines take the same job in the same minute (but not in the same millisecond) and run the job twice together, 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();

Someone can help me?

like image 738
user2717436 Avatar asked Oct 19 '22 20:10

user2717436


1 Answers

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

like image 57
user1075679 Avatar answered Nov 03 '22 08:11

user1075679