Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.template.worker.global.runner;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Optional;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
Expand Down Expand Up @@ -27,17 +31,21 @@ public class BatchJobRunner implements ApplicationRunner {
public void run(ApplicationArguments args) throws Exception {

String jobName =
args.getOptionValues("spring.batch.job.name").stream()
.findFirst()
Optional.ofNullable(args.getOptionValues("spring.batch.job.name"))
.flatMap(values -> values.stream().findFirst())
.orElseThrow(
() ->
new IllegalArgumentException(
"Missing --spring.batch.job.name"));

// invMonth가 없으면 현재 년월(yyyyMM)을 기본값으로 생성
String invMonth =
args.getOptionValues("invMonth").stream()
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Missing invMonth=yyyyMM"));
Optional.ofNullable(args.getOptionValues("invMonth"))
.flatMap(values -> values.stream().findFirst())
.orElseGet(
() ->
LocalDate.now()
.format(DateTimeFormatter.ofPattern("yyyyMM")));
Comment on lines +47 to +48
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

DateTimeFormatter 객체는 불변(immutable)이고 스레드에 안전(thread-safe)합니다. 따라서 매번 ofPattern()을 호출하여 새로 생성하는 것보다 static final 상수로 선언하여 재사용하는 것이 성능에 더 유리합니다. 클래스 수준에서 상수로 정의하여 사용하는 것을 권장합니다.

예시:

// BatchJobRunner.java 클래스에 상수 추가
private static final DateTimeFormatter YYYYMM_FORMATTER = DateTimeFormatter.ofPattern("yyyyMM");

// ... run() 메서드 내부에서 사용
.format(YYYYMM_FORMATTER)


Job job = jobRegistry.getJob(jobName);

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ spring:
name: batch-core

main:
web-application-type: none
time-zone: Asia/Seoul
jackson:
time-zone: Asia/Seoul
Expand Down
Loading