How to control the number of threads within a synchronization task

I am looking to find a way to manage multiple threads inside Asyntask.

I need to synchronize my local database with server updates. This can be big data that can be obtained using swap.

Can someone tell me what is the preferred way to control the generation flows in a loop inside asyntask so that it can display the execution dialog until the whole thread is complete.

I am a little worried about the local database object and its synchronization during the execution of various threads in order to download data from the server and save / update to the local database.

Note. I cannot download all the data from the server in one server call.

Thanks in advance.

+5
source share
2 answers

If this is lengthy work, you should use IntentService instead of AsyncTask. IntentService is an independent user interface, so you can run it in the background. To update the interface, you can send the broadcast. I use IntentService to synchronize the database. I get data from the server, and during parsing I create batch updates, and then update the local database with one batch update.

+2
source
Try this ,    

You can set a static variable that is initialized to zero, and it is incremented 
by each thread .check this variable in asynctask,if it is equal to the no: of threads 
in your class finish it.Simple But works
0
source

All Articles