user3430459 user3430459 - 1 year ago 138
Java Question

difference between android looper and executor thread pool

I was reading about loopers , and also on Executor Thread Pools and they appear to be doing the exact same thing... or am I missing something ?

Answer Source

A Looper manages tasks that a Thread will run. It puts them in a queue and then the Thread takes the next task in line. A Looper is tied to a specific Thread.

An Executor encapsulates managing and distributing tasks to different Threads. If you have a fixed threadpool size of 1 then I suppose it would be similar in design to a Looper because it will just queue up the work for that one Thread. If you have a threadpool with size > 1 then it will manage giving the task to the next Thread available to do the work, or in other words it will distribute tasks among all threads.

edit: Recommended reading:

Executors are more flexible. For Android, the only time I really use Looper is when trying to make a Handler to communicate with the main thread from a background thread (which could even be in an ExecutorService). For example:

Handler mainThreadHandler = new Handler(Looper.getMainLooper()); Runnable...); //runs on main thread
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download