2011-01-12 89 views
2

我想看看是否有可能創建一個Spring ScheduledExecutor池。我需要的是設置一個ScheduledExecutor任務,它將定期執行特定的任務。我嘗試使用以下方式:我們可以創建一個Spring ScheduledExecutorTask池嗎?

<bean id="contentProcessorPool" 
    class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean"> 
<property name="poolSize" value="${processor.corepoolsize}"/> 
<property name="continueScheduledExecutionAfterException" value="true"/> 
<property name="scheduledExecutorTasks"> 
    <list> 
    <ref local="processor"/> 
    </list> 
</property> 

<bean id="processor" 
    class="org.springframework.scheduling.concurrent.ScheduledExecutorTask"> 
<property name="delay" value="${processor.polling.delay}"/> 
<property name="period" value="${processor.polling.period}"/> 

<property name="runnable"> 
    <ref local="contentWorker" /> 
</property> 

<bean id="contentWorker" class="com.autodesk.contentextraction.processor.ContentWorker"> 
</bean> 

但是,這將創建一個單一的ContentWorker實例,它保持在指定的時間間隔運行。我想要的是一組ContentWorker在給定時間間隔後運行。

任何指針將不勝感激。

謝謝

回答

1

如果您使用固定利率,而不是固定延遲將恰好發生在那個區間操作,而不是一個具有完整以下後。之後我不會想到你需要將其集中(手動)?

如果你不需要在你的背景文件明確的控制,你可以註釋類:

import org.springframework.stereotype.Service 
org.springframework.scheduling.annotation.Scheduled 

Class annotation: @Service 
Method annotation: @Scheduled(fixedRate=30000) 

語境:

xmlns:task="http://www.springframework.org/schema/task" 

http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task-3.0.xsd 

<task:annotation-driven /> 
相關問題