Reputation: 339
In a service windows within a IScheduler object with a lot of jobs to run each time . But when you start the work of the CPU get 100 percent usage. I want to limit the concurrent jobs run to avoid excessive resource use . The objective would be possible to run about 3 processes at a time. More or less like the standard semaforo in multithread . I'm putting an example of code to demonstrate how I'm doing the schedule :
_schedulerQuartz = StdSchedulerFactory.GetDefaultScheduler();
for(int i = 0; i <=10;i++){
TriggerBuilder triggerBuilder = TriggerBuilder.Create()
.WithIdentity("TEST"+i.toString(), "TEST"+i.toString())
.StartNow();
triggerBuilder.WithSchedule(SimpleScheduleBuilder.RepeatSecondlyForever(60));
ITrigger trigger = triggerBuilder.Build();
IJobDetail job = JobBuilder.Create(typeof(MYPROCESS))
.WithIdentity("TEST2"+i.toString(), "TEST2"+i.toString())
.UsingJobData("ClientId", 0)
.UsingJobData("UserId", 0)
.Build();
_schedulerQuartz.ScheduleJob(job, trigger);
}
_schedulerQuartz.Start();
Upvotes: 3
Views: 4132
Reputation: 6884
You should be able to create this limit by defining thread pool size to be 3. There won't more than three threads to service the requests and thus only three jobs can be running at the same time. Do note that this will probably lead to misfires and misfire policies need to be in place.
NameValueCollection properties = new NameValueCollection();
properties["quartz.threadPool.threadCount"] = "3";
ISchedulerFactory sf = new StdSchedulerFactory(properties);
IScheduler sched = sf.GetScheduler();
Upvotes: 4