2010-02-24 5 views
12

튜토리얼 스프링 배치 프로젝트를 성공적으로 설정했습니다. "스프링 레벨"에서 멀티 스레드 화가 가능한지 알고 싶습니다.스프링 배치에서 멀티 스레딩을 설정하는 방법은 무엇입니까?

기본 아이디어는 작업 또는 작업 단계 목록을 만들어 독립적 스레드, 이상적으로는 'n'개의 스레드로 제한된 독립적 인 스레드에 의해 선택 및 작업되도록하는 것입니다.

이것이 가능합니까? 그렇다면 어떻게? 누군가 내가 현재 어디에서 왔는지 그 지점을 안내 해줄 수 있습니까?

내가 가지고있는 간단한 프로젝트는이 튜토리얼 here입니다. 기본적으로 화면에 메시지를 출력하는 다른 작업이 있습니다.

<import resource="applicationContext.xml"/> 

    <bean id="hello" class="helloworld.PrintTasklet"> 
     <property name="message" value="Hello"/> 
    </bean> 

    <bean id="space" class="helloworld.PrintTasklet"> 
     <property name="message" value=" "/> 
    </bean> 

    <bean id="world" class="helloworld.PrintTasklet"> 
     <property name="message" value="World!\n"/> 
    </bean> 

    <bean id="taskletStep" class="org.springframework.batch.core.step.tasklet.TaskletStep" > 
     <property name="jobRepository" ref="jobRepository"/> 
     <property name="transactionManager" ref="transactionManager"/> 
    </bean> 

    <bean id="simpleJob" class="org.springframework.batch.core.job.SimpleJob"> 
     <property name="name" value="simpleJob" /> 
     <property name="steps"> 
      <list> 
       <bean parent="taskletStep"> 
        <property name="tasklet" ref="hello"/> 
       </bean> 
       <bean parent="taskletStep"> 
        <property name="tasklet" ref="space"/> 
       </bean> 
       <bean parent="taskletStep"> 
        <property name="tasklet" ref="world"/> 
       </bean> 
      </list> 
     </property> 
     <property name="jobRepository" ref="jobRepository"/> 
    </bean> 

내 appContext이 작업 저장소 콩 (SimpleJobRepository), 트랜잭션 관리 (ResourceLessTransactionManager) 및 작업 실행 (SimpleJobLauncher)를 포함

다음은 작업의 세부 사항을 포함 내 현재 simpleJob.xml 파일입니다. 원하는 경우이 코드를 제공 할 수 있습니다. XML을 사용하여이 게시물을 꼼짝 못하게하고 싶었습니다.

도움을 주셔서 대단히 감사합니다!

답변

10

스플릿을 생성하면 다른 브랜치간에 멀티 스레딩을 사용할 수 있습니다. TaskExecutor를 사용하여 병렬 처리 정책을 정의하십시오.

Multi-threaded Step 당신이 멀티 스레딩과 MapJobRepository를 (이전의 최신 버전으로,이 JobRepository는 스레드 안전하지 않은) 사용하려면 스프링 배치의 최신 버전을 사용하십시오 참조하십시오.

4

Jean answers를보세요. ' 쉬운 방법은 SimpleAsyncTaskExecutor의 빈을 생성하고,이 빈을 사용하기위한 태스크 릿릿을 연결하는 것이다.

<bean id="simpleTaskExecutor" 
    class="org.springframework.core.task.SimpleAsyncTaskExecutor"> 
    <property name="concurrencyLimit" value="10"/> 
</bean> 

<batch:job id="jobTest"> 
    <batch:step id="step1"> 
    <!-- throttle-limit default is 4. Increase this to ensure that a thread pool is fully utilized --> 
     <batch:tasklet task-executor="simpleTaskExecutor" throttle-limit="20"> 
      <batch:chunk /> 
     </batch:tasklet> 
    </batch:step> 
</batch:job> 
관련 문제