2015-05-14 53 views
0

我用下面的任務啓動器啓動我的春天批處理作業:廣東話配置Spring Batch的運行作業因此

<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> 
    <property name="jobRepository" ref="jobRepository"/> 
    <property name="taskExecutor"> 
     <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"/> 
    </property> 
    </bean> 

和我的工作定義是

<job id="bulkExportJob" restartable="false" xmlns="http://www.springframework.org/schema/batch"> 
    <description>Exports an application to pdf in a bulk operation</description> 

    <step id="startExport" next="exportFileTree"> 
     <description>Do something to start the export</description> 
     <tasklet ref="startBulkActionTasklet"/> 
    </step> 

    <step id="exportFileTree" next="zipFileTree"> 
     <description>Export the application</description> 
     <tasklet> 
     <chunk reader="bulkActionTargetReader" writer="bulkExportFileTreeWriter" commit-interval="1" skip-limit="100000000"> 
      <skippable-exception-classes> 
      <!-- Exceptions are handled internally to the Writer so exception should not be treated as failures --> 
      <include class="java.lang.Exception"/> 
      </skippable-exception-classes> 
     </chunk> 
     </tasklet> 
     <listeners> 
     <listener ref="promotionListener"/> 
     </listeners> 
    </step> 

    <step id="zipFileTree" next="sendEmail"> 
     <description>Creates a zip file</description> 
     <tasklet ref="bulkExportZipWriter"/> 
    </step> 

    <step id="sendEmail" next="finishExport"> 
     <description>Send notification email</description> 
     <tasklet ref="bulkExportSendNotification"/> 
    </step> 


    <step id="finishExport"> 
     <description>Finalise the export</description> 
     <tasklet ref="finishBulkActionTasklet"/> 
    </step> 

    </job> 

我的目的是運行一個作業一次排隊所有其他傳入作業。但是從日誌文件中我可以看到所有作業都並行運行。正如你從代碼片段中看到的,我沒有任何額外的代碼來並行執行spring批處理,但它仍然有效。你能指點我做錯了什麼嗎?

回答

1

您正在使用SimpleAsyncTaskExecutor這是正在運行的作業異步併爲每個作業都創建新的線程:

TaskExecutor的實現,它觸發了一個新的線程爲每個任務, 異步執行它。

支持通過「concurrencyLimit」 bean屬性限制併發線程。默認情況下,併發線程數量爲 無限制。

注意:此實現不重用線程!請考慮使用 線程池TaskExecutor實現,特別是執行大量短期任務的 。

至於建議,如果你確實需要SimpleAsyncTaskExecutor可以設置concurrencyLimit爲1(與throttle-limit="1"屬性),並具有在時間1點的工作,但你可以使用默認SyncTaskExecutor將順序運行工作,當一個人完成其它會運行(根據你想要的解釋猜測)。