코루틴(2)
-
[Android Kotlin Coroutine] 코루틴 기본정리 (CoroutineContext, Coroutine Builder, CoroutineScope, Coroutine Job, CoroutineDispatcher)
Coroutine 비동기적으로 실행되는 코드를 간소화하기 위해 Android에서 사용할 수 있는 동시 실행 설계 패턴 CoroutineContext interface CoroutineContext CoroutineContext는 다양한 요소의 집합으로 코루틴의 동작을 정의합니다. Job: 코루틴의 수명 주기 제어 CoroutineDispatcher: 적절한 스레드에 작업 전달 CoroutineName: 디버깅에 유용한 코루틴 이름 CoroutineExceptionHandler: 포착되지 않은 예외 처리 Coroutine Builder (launch, async)는 CoroutineContext 값을 optional로 지정할 수 있고 이를 통해 dispatcher 를 지정할 수 있다. fun main() ..
2022.01.18 -
[AAC/Room] Exception - Cannot access database on the main thread since it may potentially lock the UI for a long period of time. 해결 방법
1. Exception 확인 java.lang.IllegalStateException: Cannot access database on the main thread since it may potentially lock the UI for a long period of time. 2. 발생 원인 Room 사용 시 쿼리 호출을 MainThread에서 실행했을 경우 발생 3. 해결 방법 allowMainThreadQueries() 메서드를 사용하면 간단하게 해결할 수 있지만 메인 스레드에서 많은 양의 쿼리문을 실행하다 보면 ui가 오랜 기간 동작하지 않을 수 있으므로 사용하면 안 되는 방법이다! 이외에 AsyncTask, RxJava, Coroutine, JavaThread를 사용하여 해결할 수 있습니다 오늘 ..
2020.06.10