Android : Parallel execution of functions in android main class

on Sunday, September 28, 2014


In my app I have 6 Arrays which should be updated each time my main activity starts. They all updated with main thread now and this leads to degradation in my app speed. Here is my dbUpdate() function:



private void dbUpdate(){
dateDB = getDateValues();
valueDB = getValues();
catDB = getCatValues();
catIndexDB = getCatIndex();
catExpenseDB = getCatExpense();
catLimitDB = getCatLimits();
}


These arrays have no dependency on eath other and I want to update them 6 parallel thread. I read this article and tried to put each array get function in a Runnable:



Runnable run6 = new Runnable(){
@Override
public void run(){
catLimitDB = getCatLimits();
}
};


So now I have six Runnable and one Handler and I changed my dbUpdate() function:



private void dbUpdate(){
hand.post(run1);
hand.post(run2);
hand.post(run3);
hand.post(run4);
hand.post(run5);
hand.post(run6);
}


But when I run my app I feel no difference. Can someone help me with this? And I should mention that this is my first experience with multithread programming.


0 comments:

Post a Comment