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

What is a ThreadPool ? And is it more effe...

Câu trả lời

A ThreadPool is a managed collection of threads that runs tasks in parallel from a queue[1]. New tasks are executed on existing threads as those threads become idle. Using a ThreadPool is more effective than creating several separate threads for the following reasons:

  • Creating threads is expensive, so you should create a ThreadPool only once as your app initializes[1]. Reusing threads in a pool is more efficient than creating and destroying threads for each task.

  • Threads are not free - they take up memory. Each thread costs a minimum of 64k of memory. This adds up quickly across the many threads in an app[2]. A ThreadPool allows you to limit the number of threads to the minimum needed for your workload.

  • CPUs can only handle a small number of threads in parallel before running into priority and scheduling issues[2]. A ThreadPool allows you to control the number of threads to avoid overloading the CPU.

  • Many system processes and third-party libraries often spin up their own ThreadPools[2]. Reusing an existing T...

senior

senior

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

middle

Explain String vs StringBuilder vs SpannedString vs SpannableString vs SpannableStringBuilder vs
CharSequence ?

middle

What is the difference between Handler vs AsyncTask vs Thread ?

junior

What is an Intent in Android?

Bình luận

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

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