Câu hỏi phỏng vấn Kotlin
Câu hỏi

What is the difference between suspending vs. blocking?

Câu trả lời

The main difference between suspending and blocking in Kotlin coroutines is:

  • Suspending a coroutine allows it to pause execution at certain points without blocking a thread, enabling other coroutines to run on the same thread[1][2]. Suspending is accomplished using the suspend keyword on functions that can pause coroutines, like delay() or withContext()[2].

  • Blocking a thread, on the other hand, halts execution and prevents other work from being done on that thread until the blocking operation completes[1]. Blocking can occur when using regular Java I/O methods or Thread.sleep() inside a coroutine[1][2].

When a coroutine suspends, it saves its state and local variables, allowing the thread to be returned to the pool to run other coroutines[4]. The coroutine can then be resumed later on ...

middle

middle

Gợi ý câu hỏi phỏng vấn

senior

How can I create static method for enum in Kotiln?

middle

What is the idiomatic way to deal with null able values, referencing or converting them?

junior

What is the idiomatic way to remove duplicate strings from array?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào