What change did really Android team make in Async task after android 2.3. When I executed the following code I am getting same result in both Android 2.3 and 3.0.
package com.sample.asynctask;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
public class AsyncTaskTestActivity extends Activity {
private static final String TAG = "AsyncTaskTestActivity";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//ExecutorService executorService = Executors.newFixedThreadPool(1);
for (int i = 1; i <= 20; i++) {
TestTask testTask = new TestTask(i);
testTask.execute();
}
}
private static class TestTask extends AsyncTask<Void, Integer, Void> {
int i;
public TestTask(int i) {
Log.i(TAG, "Constructor for " + i);
this.i = i;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
Log.i(TAG, "onPreExecute for " + i);
}
@Override
protected Void doInBackground(Void... params) {
Log.i(TAG, i + " Thread goes to sleep");
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.i(TAG, i + " Thread wakes up");
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Log.i(TAG, "onPostExecute for " + i);
}
}
}
My assumption in Gingerbread: 5 Async task executes at one thread pool at a time. My assumption in Honeycomb: 1 Async task executes at one thread pool at a time. Exactly like concurrent execution.
But, both Gingerbread and Honeycomb executes 5 Async tasks at the same time.
And also when the number for Async task is increased to 140.i am not getting java.util.concurrent.RejectedExecutionException
.
Whether my assumptions are correct? What is really happening inside there?