비동기식으로 jobLauncher 실행시키는 것 관련 질문 드립니다.
800
5 asked
Answer 1
0
네
Job 을 비동기식으로 실행한다는 의미는 Job 의 시작부터 종료까지 포함한 모든 작업을 별도의 스레드에서 실행한다는 의미입니다.
(new Runnable() {
@Override
public void run() {
try {
if (logger.isInfoEnabled()) {
logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters
+ "]");
}
job.execute(jobExecution);
if (logger.isInfoEnabled()) {
Duration jobExecutionDuration = BatchMetrics.calculateDuration(jobExecution.getStartTime(), jobExecution.getEndTime());
logger.info("Job: [" + job + "] completed with the following parameters: [" + jobParameters
+ "] and the following status: [" + jobExecution.getStatus() + "]"
+ (jobExecutionDuration == null ? "" : " in " + BatchMetrics.formatDuration(jobExecutionDuration)));
}
}
catch (Throwable t) {
if (logger.isInfoEnabled()) {
logger.info("Job: [" + job
+ "] failed unexpectedly and fatally with the following parameters: [" + jobParameters
+ "]", t);
}
rethrow(t);
}
}
private void rethrow(Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
else if (t instanceof Error) {
throw (Error) t;
}
throw new IllegalStateException(t);
}
});
}
위 구문에서
job.execute(jobExecution);
구문은 메인 스레드가 아닌 taskExecutor 에서 생성한 다른 스레드가 실행하고 있습니다.
그렇기 때문에 메인스레드가 taskExecutor.execute() 를 실행한 즉시 다음 처리가 이루어지고 Job 은 별도의 스레드 내에서 작업이 이루어지므로 Job 의 모든 처리는 비동기가 됩니다.
아시겠지만 비동기로 실행한 후에는 동기로 전환할 수 없습니다.
일단 메인 스레드가 먼저 처리가 완료되더라도 Job 은 비동기로 모든 작업이 완료될 때까지 백그라운드에서 처리가 진행 됩니다.
스레드 관점에서 동기와 비동기에 대한 개념을 확실하게 이해하는 것이 중요합니다.
스프링 배치 버전 질문
0
120
1
소스코드가 어디에 있나요?
0
95
2
트랜잭션 예외
0
90
1
질문이 있습니다.
0
128
2
ChunkListener 에서 beforeChunk 의 실행 시점 관련 질문
0
124
2
여러 JOB 설정하는법
0
148
2
강의 자료 다른 방법 있을까요?
0
154
1
JobExecution과 JobExecutionContext와의 관계
0
185
2
특정 job만 실행
1
248
1
Batch 성능 질문
0
151
1
ItemReaderAdapter 종료
0
78
1
[ 강좌 Git 브랜치 문의 ] 섹션 9 > JdbcCursorItemReader, JpaCursorItemReader
0
178
2
Spring Batch 배포 질문
0
245
2
spring batch 버전
0
235
2
retry count 관련 질문
0
170
2
StepExecutionListener 의 afterStep 에서 return ExitStatus.FAILED 에 의한 동작에 의문이 갑니다.
0
327
2
jdbc, jpa 커서방식 조회 방식 차이 질문 (강사님께 답변 받고 싶습니다)
0
233
2
Multithread step과 AsyncItemProcessor
0
201
2
job 재실행
0
250
2
bean 생명주기 문제 도와주세요(@Scope("step"), @Autowired)
0
182
1
step-in-muti-thread 질문
0
114
1
Multi-threaded-step과 Partitioning 차이 확인
0
172
2
jdbcCursorReader, jdbcPagingReader 질문
0
143
1
step muti-thread 질문
0
106
1

