In an app of mine I've successfully implemented the "Pipeline Thread" concurrency pattern to execute certain tasks in sequence (in a queue):
@Override
public void run() {
try {
Looper.prepare();
handler = new Handler();
Looper.loop();
} catch (Throwable t) {
Log.e(TAG, "halted due to an error", t);
}
}
then, to schedule an operation:
handler.post(new Runnable() {
@Override
public void run() {
// this will be done in the Pipeline Thread
}
});
with
handler = new Handler();
declared into the activity’s onCreate()
(ref: http://mindtherobot.com/blog/159/android-guts-intro-to-loopers-and-handlers/)
What I'm trying to figure out is if I can some way tweak this pattern to execute a (fixed) maximum number of those tasks at the same time, as it happens with AsyncTask and the THREAD_POOL_EXECUTOR, as seen here: https://stackoverflow.com/a/9509184/1865860
The problem is that I don't have any idea (and knowledge) about where to start to take a cue on this.
Any help is much appreciated. Thanks.