Reputation: 229
I know Android's ContentProvider is known for multiple write from multi-process/multi-thread without throwing lock exception. In multithreaded environment it might have synchronized the method using read-write lock. But what about multi process where multiple object will be created. Can any one let me internal working of ContenProvider.
Upvotes: 3
Views: 977
Reputation: 400
A ContentProvider is a manifest declared component, it is instantiated by the OS and is tied to the main process (unless the attribute process
is specified differently). Therefore only a single instance of a declared ContentProvider
is created during the life time of that application process. Other processes that wish to interact with it must go through the ContentResolver which in turn just communicate with that single provider created.
Note that when a provider is used from another process it is communicating via IPC (via Binders specifically), which means a provider's methods will be invoked in a BinderThread
during an IPC call. There is a pool of binder threads so that there can be some concurrent communication with multiple application, meaning appropriate synchronization should be done.
In summary, content providers are safe for multi-process & multi-thread interactions because:
Upvotes: 2