我在单声道中使用 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 中发生?
谢谢