My requirement is get state of all same async class call same time in loop.
for (int i = 0; i < numberOfTasks; i++) {
int taskId = i + 1;
startTask(taskId, taskDuration, useParallelExecution);
}
private void startTask(int taskId, int taskDuration, boolean useParallelExecution) {
TestTask task = new TestTask(taskId, taskDuration);
if (useParallelExecution) {
// this type of executor uses the following params:
//
// private static final int CORE_POOL_SIZE = 5;
// private static final int MAXIMUM_POOL_SIZE = 128;
// private static final int KEEP_ALIVE = 1;
//
// private static final ThreadFactory sThreadFactory = new ThreadFactory() {
// private final AtomicInteger mCount = new AtomicInteger(1);
//
// public Thread newThread(Runnable r) {
// return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
// }
// };
//
// private static final BlockingQueue<Runnable> sPoolWorkQueue =
// new LinkedBlockingQueue<Runnable>(10);
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
// this is the same as calling task.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
task.execute();
}
}
private class TestTask extends AsyncTask<Void, Void, Void> /* Params, Progress, Result */ {
private final int id;
private final int duration;
TestTask(int id, int duration) {
this.id = id;
this.duration = duration;
}
@Override
protected Void doInBackground(Void... params) {
int taskExecutionNumber = executedTasksCount.incrementAndGet();
log("doInBackground: entered, taskExecutionNumber = " + taskExecutionNumber);
SystemClock.sleep(duration); // emulates some job
log("doInBackground: is about to finish, taskExecutionNumber = " + taskExecutionNumber);
return null;
}
private void log(String msg) {
Log.d("TestTask #" + id, msg);
}
}
Here i have to get state for all TestTask async class call simultaneously. I have done lots of R&D on it but not getting any solution. Anybody know how to get state of same async class call simultaneously then help me.
Thank you in advance.