Thursday 12 July 2012

Remote service and threads

Question-1 : If some android application use remote service binder, does that binder methods get invoked in a new thread ?
Answer-1 : Yes, if some android application A invokes remote service binder methods then those methods get invoked in a new thread of that process. As that remote service is running in a separate process android creates a new thread from the thread pool of the process. But the calling thread of the application is kept blocked until remote service binder method returns. That means though android creates a new thread but the calling thread is kept blocked so do not invoke remote service binder methods from UI/Main thread of the application.

Question-2 : If some application A uses remote service binder and that remote service is part of this application A itself but running in a separate process, does that binder methods get invoked in a new thread ?
Answer-2 : its same as Answer-1. But think why do you need remote service in this scenario. Ideally remote service is not required here. Normal binder service is a solution for this scenario.

Question-3If some application A uses remote service binder and that remote service is part of this application A itself and running in a same process of application, does that binder methods get invoked in a new thread ?
Answer-3 : No, binder methods will not be invoked in a separate thread. It will be invoked in a caller thread itself.

Question-4If some application A uses remote service binder and that remote service is running in a same process of another application B, does that binder methods get invoked in a new thread ?
Answer-4its same as Answer-1. So either remote service is running in a separate process or another hosting application's process android creates a new thread from that process's thread pool and block the calling thread until binder method returns.


No comments:

Post a Comment