1

我在单声道中使用 Quartz.net。当我创建这样的调度程序时:

ISchedulerFactory quartzSchedulerFactory = new StdSchedulerFactory();
IScheduler quartzScheduler = quartzSchedulerFactory.GetScheduler();

在 Quartz.Net 中,SimpleThreadPool 类中调用了以下方法:

/// <summary>
/// Called by the QuartzScheduler before the <see cref="ThreadPool" /> is
/// used, in order to give the it a chance to Initialize.
/// </summary>
public virtual void Initialize()
{
    if (workers != null && workers.Count > 0) 
    {
        // already initialized...
        return;
    }

    if (count <= 0)
    {
        throw new SchedulerConfigException("Thread count must be > 0");
    }

    // create the worker threads and start them
    foreach (WorkerThread wt in CreateWorkerThreads(count))
    {
        wt.Start();

        availWorkers.AddLast(wt);
    }
}

在 Windows 中这工作正常,但在 CentOS 中,调用 wt.Start() 时系统会冻结。即使我杀死了该进程,它也会失效,只有重新启动系统才能杀死它。尽管有时它会起作用,但我执行该程序的次数大约为五分之一。

以下是 WorkerThread 启动时调用的代码:

public override void Run()
{
    bool ran = false;
    bool shouldRun;
    lock (this)
    {
        shouldRun = run;
    }

    while (shouldRun)
    {
        try
        {
            lock (this)
            {
                while (runnable == null && run)
                {
                    Monitor.Wait(this, 500);
                }

                if (runnable != null)
                {
                    ran = true;
                    runnable.Run();
                }
            }
        }
        catch (Exception exceptionInRunnable)
        {
            log.Error("Error while executing the Runnable: ", exceptionInRunnable);
        }
        finally
        {
            lock (this)
            {
                runnable = null;
            }
            // repair the thread in case the runnable mucked it up...
            if (Priority != tp.ThreadPriority)
            {
                Priority = tp.ThreadPriority;
            }

            if (runOnce)
            {
                lock (this)
                {
                    run = false;
                }
                tp.ClearFromBusyWorkersList(this);
            }
            else if (ran)
            {
                ran = false;
                tp.MakeAvailable(this);
            }
        }

        // read value of run within synchronized block to be 
        // sure of its value
        lock (this)
        {
            shouldRun = run;
        }
    }

    log.Debug("WorkerThread is shut down");
}

会不会是死锁问题?如果是,为什么它不在 Windows 中发生?

谢谢

4

1 回答 1

3

我在 CentO 中遇到了类似的问题。Mono 2.10.8.1 在创建默认线程池线程时卡住了。卡住后,无法终止进程或获取堆栈跟踪。

我已经设法通过更新操作系统的核心来解决这个问题。从 2.6.32-71.el6.x86_64 到 2.6.32-279.14.1.el6.x86_64。

于 2012-12-11T03:02:25.120 回答