Skip to content

Commit e98c16b

Browse files
committed
enable slf4j and lombok
1 parent fd6d1b0 commit e98c16b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id("java")
3+
id("io.freefair.lombok") version("8.11")
34
}
45

56
group = "io.concurrency"
@@ -10,6 +11,9 @@ repositories {
1011
}
1112

1213
dependencies {
14+
implementation("ch.qos.logback:logback-classic:1.4.1")
15+
implementation("org.slf4j:slf4j-api:2.0.3")
16+
1317
testImplementation(platform("org.junit:junit-bom:5.9.1"))
1418
testImplementation("org.junit.jupiter:junit-jupiter")
1519
}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
package io.concurrency.chapter04.exam01;
22

3-
import java.util.logging.Level;
4-
import java.util.logging.Logger;
3+
import lombok.extern.slf4j.Slf4j;
54

5+
@Slf4j
66
public class DefaultExceptionHandlerExample {
77

88
public static void main(String[] args) {
99

1010
// 모든 스레드의 예외에 대한 기본 핸들러 설정
11-
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
12-
@Override
13-
public void uncaughtException(Thread t, Throwable e) {
14-
System.out.println(t.getName() + " 에서 예외 발생 " + e);
15-
}
16-
});
11+
Thread.setDefaultUncaughtExceptionHandler(defaultThreadExceptionHandler());
1712

1813
// 예외를 발생시키는 여러 스레드
1914
Thread thread1 = new Thread(() -> {
2015
throw new RuntimeException("스레드 1 예외!");
2116
});
2217

2318
Thread thread2 = new Thread(() -> {
24-
throw new RuntimeException("스레드 2 예외!");
19+
throw new IllegalStateException("스레드 2 예외!");
2520
});
2621

2722
thread1.start();
2823
thread2.start();
2924
}
25+
26+
private static Thread.UncaughtExceptionHandler defaultThreadExceptionHandler() {
27+
return (thread, exception) -> log.info("{}에서 예외 발생 : {}", thread.getName(), exception.getMessage());
28+
}
3029
}

0 commit comments

Comments
 (0)