fix: EgovFixedLengthLineAggregator 멀티스레드 환경 thread-safety 개선#237
Open
z3rotig4r wants to merge 1 commit into
Open
fix: EgovFixedLengthLineAggregator 멀티스레드 환경 thread-safety 개선#237z3rotig4r wants to merge 1 commit into
z3rotig4r wants to merge 1 commit into
Conversation
고정길이 라인 집계기의 paddingList 지연 초기화가 비동기화 상태로 공유되어, 멀티스레드 step(또는 공유 빈)에서 doAggregate 동시 호출 시 부분 초기화된 리스트를 참조해 잘못된 폭의 라인을 생성하거나 예외가 발생할 수 있었습니다. 가변 공유 상태(paddingList/createPaddingList/PADDING_LISTSIZE)를 제거하고 패딩을 String.valueOf(padding).repeat(n)로 무상태 생성하도록 변경했습니다. 출력 결과는 동일하며 thread-safe 합니다. 검증: 단위 테스트 6종 추가(우측 패딩/정확폭/커스텀 패딩/100경계 초과/초과값 예외/32스레드 공유 동시성), transform 패키지 회귀 통과.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
EgovFixedLengthLineAggregator(고정길이 출력 라인 집계기)의paddingList지연 초기화가 비동기화 상태로 인스턴스에 공유되어, 멀티스레드 step(또는 공유 빈)에서doAggregate가 동시 호출될 때 thread-safety 문제가 발생합니다.문제
doAggregate는 다음과 같이 비동기화로 지연 초기화합니다.createPaddingList()는 빈 리스트를 먼저 필드에 대입한 뒤 루프로 채웁니다. 다른 스레드가paddingList != null(빈 리스트)을 보고 초기화를 건너뛰면, 부분 초기화된 리스트에paddingList.get(...)을 수행하여 다음이 발생할 수 있습니다.IndexOutOfBoundsException/ConcurrentModificationExceptionEgovFixedLengthLineAggregator는DefaultItemWriter가 writer당 1개 인스턴스를 생성해 step의 모든 라인 집계에 공유하므로, taskExecutor 기반 멀티스레드 step에서 이 경로에 도달합니다.변경
가변 공유 상태(
paddingList/createPaddingList()/PADDING_LISTSIZE)를 제거하고, 패딩을String.valueOf(padding).repeat(needPaddingSize)로 무상태 생성하도록 변경했습니다..repeat()는 동일 클래스에서 이미 사용 중이며 Java 11+ 표준 API입니다(본 실행환경 Java 21 타깃)검증
EgovFixedLengthLineAggregatorTest6종 추가:PADDING_LISTSIZE(100) 분기 경계를 넘는 폭(250) 동작 보존IllegalStateException)transform 패키지 회귀 테스트 통과(
BUILD SUCCESS).