kotlin 비동기 처리1 [Kotlin] 스레드간 동기화 방법 1. Synchronized 메서드: class MyRunnable : Runnable { private var sharedVariable = 0 // synchronized 메서드 @Synchronized private fun increment() { sharedVariable++ } override fun run() { for (i in 0 until 10000) { increment() } } } 2. Synchronized 블록: class MyRunnable : Runnable { private val lock = Any() private var sharedVariable = 0 override fun run() { for (i in 0 until 10000) { synchronized(lock.. 2023. 11. 22. 이전 1 다음