1
我在單聲道中使用Quartz.net。 當我創建這樣的調度:Quartz.Net in Mono開始線程凍結系統
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中發生?
謝謝
謝謝,這工作。 –