tjb
tjb

Reputation: 11728

Android: Is it ok to have multiple handlers per thread

Is it a bad practice to have multiple objects on a thread instantiating and using there own private handlers? Is an application supposed to instantiate and use only one handler per thread and pass it around among objects?

Upvotes: 2

Views: 1509

Answers (2)

Jiaqi Liu
Jiaqi Liu

Reputation: 629

There are benefits to have multiple Handlers per Looper/MessageQueue pair. You can send and handle different categories of Runnables or Messages on respective handlers, which reduces the number of if else to make you program more maintainable.

Upvotes: 3

Nicholas Jordan
Nicholas Jordan

Reputation: 656

remarkably - contrary to what you might think and what most people will tell you a "small thread pool" or some variation of the idea that you can understand is actually remarkably effective at maintaining overall robustness and responsiveness ~ in fact it is not only harmless but probably a good idea to try however they have their main() as doing nothing but starting a Thread Runnable and just see what it does on a prototyping bench platform as the approach most would tend to use can "trap" the main in deep convoluted heavy processor load and throw an ANR - the sooner you can release the main thread probably the better

has to be tested though

Upvotes: 1

Related Questions