In my application I have to load data from about 20 text files in the beginning, only once. I was using Asynctasks on AsyncTask.THREAD_POOL_EXECUTOR first, but the KEEP_ALIVE_TIME for each asynctask was an issue, destroying asynctasks which were queued for long. Is there a way to change this default KEEP_ALIVE_TIME? Please tell me if so. Right now I have switched to the following code: -
public class DBLoader {
public static int completed = 0;
public static int nthreads;
Executor executor;
public DBLoader(int nthreads) {
executor = java.util.concurrent.Executors.newFixedThreadPool(nthreads);
this.nthreads = nthreads;
}
public void startThread(Thread thread){
executor.execute(thread);
}
}
Each of my threads reads a file from raw resource and puts it into local db.
InputStream is = InputStreamReader(context.getResources().openRawResource(R.raw.filename));
Right now it takes about 50 seconds for this on MOTO G1, when I am reading 8 files. And it it not acceptable. Please suggest a better way to do this. I am using greendao for implementing the local db. Thanks in advance.