Questions regarding Threading. The structure of my code is...
The UI thread calls a Routine R0 which *uses a background thread* to call two Routines R1 and R2 which each need to retrieve information from the internet. R1 and R2 are called in succession. R1 must complete before R2 is called. This sequence is done in a loop, with each iteration selecting the next item from an ArrayList to operate on.
*Note* I believe that R0 does not need to use a background thread as it is R1 and R2 which go to the internet. But it works in simple testing so I'll leave it as is for now.
R1 and R2 each extend Thread, so each begins with a public void run() {...}. Also each needs to store a result on the UI thread so each uses a runOnUiThread(new Runnable(...)) at the end of its processing.
All of the code works perfectly (with a bit of cheating, a finite loop after calls to R1 and R2 waiting for the result) when tested in a simple environment where there is no possibility of a conflict. When installed in the App it works perfectly for the first iteration then the App "hangs" - it does not finish the next
iteration, it literally just sits there; no processing is going on as the LogCat has paused; and the program does respond to other menu selections correctly - so it has not "crashed";
I have not been this deep into Threads so I have been reading and getting confused by several blogs posts etc on the topic of Threads, so I have some questions...
Do I need to use a thread pool?
Will I need to use a Scheduler?
Does anyone have a favorite, good basic introduction to this topic? Especially one with an introductory level example?
Hopefully, next time I will have some code to show
Thank you,
Mick