Skip to content

Instantly share code, notes, and snippets.

@gunkim
Created April 18, 2023 16:41
Show Gist options
  • Save gunkim/af1c0123ffcebee5648197207c3502e9 to your computer and use it in GitHub Desktop.
Save gunkim/af1c0123ffcebee5648197207c3502e9 to your computer and use it in GitHub Desktop.
스레드 타이핑 연습
package io.github.gunkim
fun main() {
val thread = Thread {
System.out.printf("현재 스레드 : %s%n", Thread.currentThread().name)
System.out.printf("현재 스레드에는 우선순위가 설정되었음. %s", Thread.currentThread().priority)
}.apply {
name = "새 작업 스레드"
priority = Thread.MAX_PRIORITY
uncaughtExceptionHandler = Thread.UncaughtExceptionHandler { t: Thread, e: Throwable ->
System.out.printf(
"예외가 발생했습니다. 스레드 : %s, 예외 : %s%n",
t.name,
e.message
)
}
}
System.out.printf("실행 전 스레드 : %s%n", Thread.currentThread().name)
thread.start()
System.out.printf("실행 후 스레드 : %s%n", Thread.currentThread().name)
Thread.sleep(10000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment