2010-06-11 54 views
0

我無法弄清楚用於調度和合並不同狀態的可運行程序(每個Runnable實例具有不同的狀態)。我可以使用ScheduledExecutorFactoryBean和MethodInvokingRunnable一起提供參數。但是請看一下關鍵的ScheduledExecutorFactoryBean方法,它的設計方式是所有任務都應該從頭開始。Spring--調度和池化不同狀態的可運行程序(每個Runnable實例有不同的狀態)

protected void registerTasks(ScheduledExecutorTask[] tasks, ScheduledExecutorService executor) { 
     for (ScheduledExecutorTask task : tasks) { 
      Runnable runnable = getRunnableToSchedule(task); 
      if (task.isOneTimeTask()) { 
       executor.schedule(runnable, task.getDelay(), task.getTimeUnit()); 
      } 
      else { 
       if (task.isFixedRate()) { 
        executor.scheduleAtFixedRate(runnable, task.getDelay(), task.getPeriod(), task.getTimeUnit()); 
       } 
       else { 
        executor.scheduleWithFixedDelay(runnable, task.getDelay(), task.getPeriod(), task.getTimeUnit()); 
       } 
      } 
     } 
} 

我想不出如何使用ThreadPoolTask​​Scheduler設置此場景。

請幫我看看這裏。謝謝


編輯:縮短的版本是:如何設置任務調度程序將運行數百個「主題的不同實例(具有不同的狀態)以2秒的間隔

+0

我認爲我可以使用AnnotationConfigApplicationContext設置ScheduledExecutorFactoryBean與多個ScheduledExecutorTasks每個具有MethodInvokingRunnable提供不同值的參數....聽起來對我好 – lisak 2010-06-11 13:45:46

+0

我的' m試圖做的是安排代表http請求(每個請求具有不同的代理和目標)的線程,每個線程在前幾秒後啓動,其中有數千個請求,連接持續長達30秒,以便我需要它併發 – lisak 2010-06-11 15:21:44

+0

現在我認爲taskSchedulers絕對不是我想要做的事。他們應該安排一個不可變的任務/ Runnable。對 ? – lisak 2010-06-11 16:29:14

回答

0

這很容易,我不知道我在想什麼,我沒有看到它:-)


我剛纔編程填補了數組ScheduledExecutorTask [] ScheduledExecutorFactoryBean與數千個任務,每個遞增的延遲特性和不同的運行的。然後,我只是用了fa ctorybean ...從春天傢伙真的很方便factorybean ...

相關問題