2012-11-14 30 views
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中發生?

謝謝

回答

3

我在CentOs有類似的問題。單聲道2.10.8.1被困在創建默認線程池線程。卡住後,不可能殺死進程或獲取堆棧跟蹤。

我已經設法通過更新OS的核心解決了這個問題。 從2.6.32-71.el6.x86_64到2.6.32-279.14.1.el6.x86_64。

+0

謝謝,這工作。 –