gpt4 book ai didi

c# - 使用集群的 Quartz.net 调度器

转载 作者:行者123 更新时间:2023-11-30 16:56:48 25 4
gpt4 key购买 nike

我正在使用集群选项,但遇到了一些问题:

  1. 当我在两台机器上使用时,我创建的作业在开始运行时与它们的定义无关。例如:如果我将作业定义为每 10 秒运行一次,它可以在开始时每两秒运行一次,并且只有从第 2 次运行它才是正确的 - 每 10 秒一次。

  2. 两台机器在同一分钟内(但不是在同一毫秒内)执行相同的作业并同时运行该作业两次,我尝试使用锁处理程序属性但可能我没有很好地定义它。 .

这是我的代码:

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();

有人可以帮助我吗?

最佳答案

我知道这是一个旧线程,但如果我们想禁止并发执行,我们必须将 DisallowConcurrentExecution 属性添加到作业类。

关于c# - 使用集群的 Quartz.net 调度器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481463/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com