tasklet에 해당하는 글 1

[Spring] Spring Batch Tasklet

JAVA/SpringBatch|2020. 2. 25. 20:07

ETL이나 각종 기능들은 결국 Tasklet을 구현하여 제공하는 기능들이며

Tasklet은 execute(S,C) 메소드 만을 제공합니다.

 

/**
* Given the current context in the form of a step contribution, do whatever
* is necessary to process this unit inside a transaction. Implementations
* return {@link RepeatStatus#FINISHED} if finished. If not they return
* {@link RepeatStatus#CONTINUABLE}. On failure throws an exception.
* 
* @param contribution mutable state to be passed back to update the current
* step execution
* @param chunkContext attributes shared between invocations but not between
* restarts
* @return an {@link RepeatStatus} indicating whether processing is
* continuable. Returning {@code null} is interpreted as {@link RepeatStatus#FINISHED}
*
* @throws Exception thrown if error occurs during execution.
*/
@Nullable
RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;

결국 리턴이 RepeatStatus.FINISHED(혹은 null) 로 리턴되면 마치게 되고 RepeatStatus.CONTINUABLE 의 경우에는 execute를 다시 호출하게 됩니다

(리턴값을 RepeatStatus.CONTINUABLE로 계속 반환하면 무한히 돌겠죠..)

 

 

Spring Batch에서 Tasklet을 imple하여 제공하고 있는 클래스 및 interface는 아래와 같습니다.

 

  • [I] Tasklet
    • [C] MethodInvokingTaskletAdapter : POJO 메소드 호출을 Step 시점에 호출하기위한 wraps 클래스
    • [C] CallableTaskletAdapter : Callable을 Step 시점에 호출하기 위한 wraps 클래스
    • [C] ChunkOrientedTasklet : ChunkProvider(SimpleChunkProvier 기준으로 ItemReader) , ChunkProcessor(SimpleChunkProcessor 기준으로 ItemProcessor, ItemWriter)를 활용하는 Tasklet(ETL)
    • [I] StoppableTasklet : (3.0부터) stop() 메소드를 구현하도록 하는 인터페이스며, 프레임워크에서 JobOperator.stop 시 해당 메소드를 불러줍니다.
      • [C] BatchletAdapter : (3.0부터) Batchlet을 지원하는 Tasklet Batchlet은 arg가 없는 process와 stop 메소드가 있는 interface 입니다.
      • [C] SystemCommandTasklet : Command(Java가 아닌 별도 프로그램을 실행한다던지)를 위한 Tasklet

 

 

'JAVA > SpringBatch' 카테고리의 다른 글

[SpringBatch] State  (0) 2020.03.25
[Spring] Spring Batch Reader Writer  (0) 2020.03.24
[Spring Batch] Flow & Step  (0) 2020.03.23
[Spring Batch] Job  (0) 2020.03.20
[Spring] Spring Batch Version History  (0) 2020.02.22

댓글()