This document describes the internals of how Asynctask of Android works internally and its similarities with half-sync half-async design pattern as described in Pattern Oriented Software Architecture or POSA2.
1. Android Asynctask Internals vis-a-vis Half Sync
Half Async pattern
by
Somenath Mukhopadhyay
som.mukhopadhyay@gmail.com
The way Asynctask has been implemented in Android, is an apt example of Half Sync Half
Async pattern described in Pattern Oriented Software Architecture or POSA2. First of all, let us
try to understand what we mean by Half SyncHalf Async design pattern. Half Sync Half Async
pattern is a specific way how we want to structure our threads in a multithreaded application. As
the name suggests, in this pattern we divide the solution of managing multiple threads into two
different specific zones one is synchronous and the other is an asynchronous zone. The main
thread communicates with a thread asynchronously and this thread is responsible for queuing
multiple tasks in a FIFO order. This thread then pushes these tasks on the synchronous layer to
different threads taken from a thread pool. These thread pools then execute these tasks
synchronously in the background. The whole process can be depicted by the following diagram.