开发者

Quartz.net causes .NET CLR LocksAndThreads

We've been using Quartz.net project to control scheduled tasks in one of our windows services. We've been using it for a while now with no problems but we've recently noticed an issue with .NET CLR LocksAndThreads.

Please see this example command line app written in C#.

using System;
using Quartz;
using Quartz.Impl;

namespace QuartzMemTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Quartz Test");
            Console.WriteLine("-----------");
            Console.WriteLine(Environment.NewLine);



            ScheduleHelper.ScheduleJob(typeof(MyTask), "MyJobName", "MyTriggerName", "0 0/01 * 1/1 * ? *");

            Console.WriteLine("开发者_如何学GoPress any key to exit...");
            Console.ReadKey();
        }
    }


    public class ScheduleHelper
    {
        /// <summary>
        /// Adds a job to the Quartz schedule
        /// </summary>
        /// <param name="job">The Job class which inherits from the Quartz.IJob interface</param>
        /// <param name="jobName">A name to give to the job</param>
        /// <param name="triggerName">A name to give to the trigger</param>
        /// <param name="triggerCronExpression">CRON expression to determine the job run interval</param>
        public static DateTime ScheduleJob(Type job, string jobName, string triggerName, string triggerCronExpression)
        {
            // Start the scheduler to run our ImportOpportunitiesJob
            ISchedulerFactory schedFact = new StdSchedulerFactory();
            IScheduler sched = schedFact.GetScheduler();
            sched.Start();

            // Create an instance of our job
            JobDetail jobDetail = new JobDetail(jobName, null, job);

            // Create a CRON trigger which determines the firing interval
            CronTrigger trigger = new CronTrigger();
            trigger.Name = triggerName;
            trigger.StartTimeUtc = DateTime.UtcNow;
            trigger.CronExpressionString = triggerCronExpression;

            // Add job and trigger to the schedule
            return sched.ScheduleJob(jobDetail, trigger);
        }
    }


    public class MyTask : IStatefulJob
    {

        public void Execute(JobExecutionContext job)
        {
            Console.WriteLine("MyTask: Doing something....");
        }

    }
}

We have noticed that if we start Performance Monitor first and then run the above sample code we can see the .NET CLR LocksAndThreads suddenly start to increase and continue to do so until the app is stopped. A colleague of mine first noticed this after one of our live servers crashed after running out of resources.

Is it Quarts causing this or something daft I am doing? If it's Quartz, is there anything different I can do to solve the issue?


We encountered a similar issue on a quartz.net project that I worked on. What we found is that the Thread pool sometimes leaks resources and doesn't clean itself up properly, under certain circumstances. I ended up implementing a new thread pool with better locking and notification of when jobs were actually complete. This resolved the issue for us.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜