[w06][minseo] Spring Event 기초 — 동기 실행, 순서 제어 및 예외 전파 메커니즘 분석#39
Open
minseokim0113 wants to merge 4 commits into
Open
[w06][minseo] Spring Event 기초 — 동기 실행, 순서 제어 및 예외 전파 메커니즘 분석#39minseokim0113 wants to merge 4 commits into
minseokim0113 wants to merge 4 commits into
Conversation
minseokim0113
marked this pull request as ready for review
June 10, 2026 17:17
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.
📅 이번 주차 개요
w06🏃♂️ 진행 상황
publishEvent+@EventListener기본 메커니즘 확인 (동기/동일 스레드)@Order를 통한 순서 제어 확인ApplicationListener인터페이스)과 새 방식(@EventListener) 비교record,String발행) 확인🛠️ 개발 환경
spring-boot-starter-web 3.4.1,starter-data-jpa,starter-jdbc,postgresqlMeasurementLog(5주차 자동 파일 저장 로직 이식 버전)⏳ 타임라인 및 시도한 내용
HelloEvent발행 시[publisher] 시작->[listener] 실행->[publisher] 끝순서 관찰. 발행자와 리스너가restartedMain스레드에서 동기적으로 동작함을 확인.MeasurementLog기능을 이식하여measurements.md자동 기록 기능 활성화.@Order를 부여하여1 -> 2 -> 3순차 실행 보장 확인.RuntimeException투척 시 L3 호출이 생략되고 발행자(Publisher)의catch블록으로 예외가 전파됨을 확인.ApplicationEvent상속 기반의 옛 방식 리스너와 어노테이션 기반 현대 방식의 호환성 및 유연성 비교.record및String타입을 활용하여 상속 없이도 이벤트 발행/구독이 가능한 Payload-only 메커니즘 관찰.해결. 5주차 Advice 안-밖 구조의 한계를 시간축 분리로 극복.
강제하여 영속성 보장 성공.
구조 학습.
📊 측정 결과 (Stage 별 리스너 호출 동작)
@Order로 순서 제어 가능record,String모두 정상 수신ApplicationEvent상속 불필요REQUIRES_NEW필수 (새 트랜잭션 필요)624ms → 2msthis.method()호출 시 비동기 무시@Async또한 프록시 기반 (Self-invocation 제약)isVirtual: true로그 확인💥 통증 / 막힌 곳 (Troubleshooting)
1. IntelliJ Gradle 인식 이슈
minseo폴더가 단순 디렉토리로 인식되어 실행 버튼이 안 뜨는 문제 발생.build.gradle추가 및 Gradle 프로젝트 Reload를 통해 소스 루트로 정상 인식시킴.2. 인프라 일관성 문제
MeasurementLog가 콘솔 출력 전용이라 파일 기록이 안 됨.3. AFTER_COMMIT 내 DB 쓰기 유실 (Silent Fail)
4. Virtual Thread 설정 덮어쓰기 이슈
💡 해결 후 인사이트
publishEvent를 통해 부수 효과가 발생함을 코드상에 명시적으로 드러냄.@Async) 전환이나 예외 처리 전략이 왜 중요한지 보여줌.multicaster는 이벤트의 타입을 보고 적절한 리스너를 찾아주므로, 복잡한 상속 계층 없이도 필요한 데이터를 전달하기 매우 편리함.📝 회고
STAGE 1을 통해 스프링 이벤트가 내부적으로 어떻게 리스너를 찾아 호출하는지, 그리고 기본적으로는 발행자와 생명주기를 같이하는 **"동기 호출"**임을 명확히 이해했다.
6주차 과정을 통해 스프링 이벤트 시스템이 단순한 '신호 전달'을 넘어, 트랜잭션의 한계를 극복하고 시스템의 성능을 비약적으로 끌어올리는 핵심 도구임을 배웠다.
특히 5주차에 고민했던 "트랜잭션 안에서 부수 효과를 어떻게 처리할 것인가"에 대한 명쾌한 해답을 찾을 수 있었다. 단순히 코드를 짜는 법을 넘어, 운영체제 수준의 스레드 모델(1:1 vs M:N)과 데이터 정합성 보장 전략을 동시에 고민해 볼 수 있었던 매우 밀도 높은 시간이었다.