Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
AsyncTask now uses the poll executor for apps up through HC MR1 and t…
Browse files Browse the repository at this point in the history
…he serialized one after that.

Change-Id: I47d135ace5f8e78e4fa44ac9d1bf7abeeb9d3ba0
  • Loading branch information
onoratoj committed Mar 18, 2011
1 parent e92f212 commit d630f10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions core/java/android/app/ActivityThread.java
Expand Up @@ -45,6 +45,7 @@
import android.net.IConnectivityManager;
import android.net.Proxy;
import android.net.ProxyProperties;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
Expand Down Expand Up @@ -3427,6 +3428,14 @@ private final void handleBindApplication(AppBindData data) {
Process.setArgV0(data.processName);
android.ddm.DdmHandleAppName.setAppName(data.processName);

// If the app is Honeycomb MR1 or earlier, switch its AsyncTask
// implementation to use the pool executor. Normally, we use the
// serialized executor as the default. This has to happen in the
// main thread so the main looper is set right.
if (data.appInfo.targetSdkVersion <= 12) {
AsyncTask.setDefaultExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}

/*
* Before spawning a new process, reset the time zone to be the system time zone.
* This needs to be done because the system time zone could have changed after the
Expand Down
11 changes: 8 additions & 3 deletions core/java/android/os/AsyncTask.java
Expand Up @@ -153,7 +153,6 @@ public abstract class AsyncTask<Params, Progress, Result> {
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);

Expand Down Expand Up @@ -183,6 +182,7 @@ public Thread newThread(Runnable r) {

private static final InternalHandler sHandler = new InternalHandler();

private static volatile Executor sDefaultExecutor = SERIAL_EXECUTOR;
private final WorkerRunnable<Params, Result> mWorker;
private final FutureTask<Result> mFuture;

Expand Down Expand Up @@ -240,6 +240,11 @@ public static void init() {
sHandler.getLooper();
}

/** @hide */
public static void setDefaultExecutor(Executor exec) {
sDefaultExecutor = exec;
}

/**
* Creates a new asynchronous task. This constructor must be invoked on the UI thread.
*/
Expand Down Expand Up @@ -496,7 +501,7 @@ public final Result get(long timeout, TimeUnit unit) throws InterruptedException
* {@link AsyncTask.Status#RUNNING} or {@link AsyncTask.Status#FINISHED}.
*/
public final AsyncTask<Params, Progress, Result> execute(Params... params) {
return executeOnExecutor(THREAD_POOL_EXECUTOR, params);
return executeOnExecutor(sDefaultExecutor, params);
}

/**
Expand Down Expand Up @@ -559,7 +564,7 @@ public final AsyncTask<Params, Progress, Result> executeOnExecutor(Executor exec
* a simple Runnable object.
*/
public static void execute(Runnable runnable) {
THREAD_POOL_EXECUTOR.execute(runnable);
sDefaultExecutor.execute(runnable);
}

/**
Expand Down

0 comments on commit d630f10

Please sign in to comment.