2014-03-03 5 views
6

목록을 읽고 목록의 각 항목에 대해 하나 이상의 단계를 반복해야하는 스프링 배치 작업을 구현하려면 어떻게해야합니까?목록의 각 항목에 대한 스프링 배치 흐름 단계 반복

현재 한 단계로 목록을 읽고 나서 작업 컨텍스트에 넣습니다. 하지만 작업 컨텍스트는 DB에 유지되고 너무 커지면 CLOB를 사용해야하고 액세스 권한이 없습니다.

그래서 전체 목록을 작업 컨텍스트에 저장하는 것을 포함하지 않는 솔루션을 찾고 있습니다.

물론 로컬 변수에 목록을 넣을 수 있습니다. 그러나 스프링 배치와 같은 옵션이 더 있는지 궁금합니다.

+1

당신이 항목 프로세서를 체인으로 간주 있나요? http://docs.spring.io/spring-batch/reference/html/readersAndWriters.html#chainingItemProcessors –

+0

내 직업은 다음과 같아야합니다. 1. 읽기 목록 2. 목록에서 항목 하나를 가져 와서 처리하십시오. 3. reader -> processor -> writer 4. 목록에 항목이 더 있으면 2 단계에서 반복하십시오. 그래서 어떤 프로세서도 연결할 수 없습니다. –

+0

그 말은 상당히 일반적인 작업 프로세스처럼 들립니다. 읽기 -> 프로세스 -> 쓰기. 문제가 무엇인지 알 수없는 점은 무엇입니까? –

답변

2

가장 먼저 동의 한 경향이있는 작업에 대한 위의 설명과는 별도로 최신 3.0.0.M3을 사용하는 경우 컬렉션을 보유 할 수있는 JobScope 컨테이너를 만들 수 있습니다 다양한 단계를 반복하면됩니다. 거기에서 외부 소스 대신 해당 컨테이너를 읽고 처리/작성할 수 있습니다.

+0

스프링 배치 3을 사용할 수 없어서 작업 범위가 없습니다. 지금까지 찾은 최고의 해결책은 작업 실행 ID에 연결된 다른 모음에 목록을 저장하는 것입니다. 일자리 구조 조정과 관련하여 이것이 어떻게 도움이되는지를 알지 못합니다. 목록이 있습니다. 각 항목에 대해 로컬로 원격 파일을 복사 한 다음 STAX 판독기를 사용하여 다음 프로세스를 읽고 각 항목을 내 DB에 씁니다. 그리고 나는 이것을 반복한다. 메모리에 저장하거나 임시로 DB에 저장하는 데 너무 많은 데이터가 있습니다. –

2

Spring Batch-Repeat step for each item in a data list 질문에서 논의 된 것처럼 Partitioning이 해결책 인 것 같습니다. PartitionHandler에 대한

구성 :

 <batch:step id="anyNameJobMaster"> 
      <batch:partition step="nameOfActualStepToBeIterated" partitioner="partitioner"> 
       <batch:handler grid-size="10" task-executor="taskExecutor" /> 
      </batch:partition> 
     </batch:step> 

     <bean id="partitioner" class="org.example.PartitionerThatImplementsPartitioner" lazy-init="true" scope="step"/> 

PartitionHandler 샘플 코드 :

public class PartitionerThatImplementsPartitioner implements Partitioner{ 
    @Override 
    public Map<String, ExecutionContext> partition(int gridSize) { 
     Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize); 
     //Iteration goes here 
     //For Each Iteration, create ExecutionContext and add it to map. 
     map.put("somePartionKeyString", new ExecutionContext().put("ContextIdentifiere.g.FileName", "IteratedVale.g.FilePath")) 

    } 
} 

작업 구성 :

 <batch:step id="nameOfActualStepToBeIterated"> 
     <batch:tasklet transaction-manager="someTxManager"> 
      <batch:chunk processor="someProcessor" 
       writer="itemWriter" commit-interval="${commitInterval}"> 
       <batch:reader> 
        <bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> 
         <property name="resource" value="#{stepExecutionContext['ContextIdentifiere.g.FileName']}" />      
        </bean> 
       </batch:reader> 
      </batch:chunk> 
     </batch:tasklet> 
관련 문제