|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectnet.tsz.afinal.core.AsyncTask<Params,Progress,Result>
Params - Progress - Result - public abstract class AsyncTask<Params,Progress,Result>
拷贝 https://android.googlesource.com/platform/frameworks/base/+/jb-release/ core/java/android/os/AsyncTask.java 修改了线程池属性,让并发线程按顺序执行
| 嵌套类摘要 | |
|---|---|
static class |
AsyncTask.Status
Indicates the current status of the task. |
| 字段摘要 | |
|---|---|
static java.util.concurrent.Executor |
DUAL_THREAD_EXECUTOR
|
static java.util.concurrent.Executor |
SERIAL_EXECUTOR
An Executor that executes tasks one at a time in serial
order. |
static java.util.concurrent.Executor |
THREAD_POOL_EXECUTOR
An Executor that can be used to execute tasks in parallel. |
| 构造方法摘要 | |
|---|---|
AsyncTask()
Creates a new asynchronous task. |
|
| 方法摘要 | |
|---|---|
boolean |
cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task. |
AsyncTask<Params,Progress,Result> |
execute(Params... params)
Executes the task with the specified parameters. |
static void |
execute(java.lang.Runnable runnable)
Convenience version of execute(Object...) for use with
a simple Runnable object. |
AsyncTask<Params,Progress,Result> |
executeOnExecutor(java.util.concurrent.Executor exec,
Params... params)
Executes the task with the specified parameters. |
Result |
get()
Waits if necessary for the computation to complete, and then retrieves its result. |
Result |
get(long timeout,
java.util.concurrent.TimeUnit unit)
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result. |
AsyncTask.Status |
getStatus()
Returns the current status of this task. |
static void |
init()
|
boolean |
isCancelled()
Returns true if this task was cancelled before it completed normally. |
static void |
setDefaultExecutor(java.util.concurrent.Executor exec)
|
| 从类 java.lang.Object 继承的方法 |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 字段详细信息 |
|---|
public static final java.util.concurrent.Executor THREAD_POOL_EXECUTOR
Executor that can be used to execute tasks in parallel.
public static final java.util.concurrent.Executor SERIAL_EXECUTOR
Executor that executes tasks one at a time in serial
order. This serialization is global to a particular process.
public static final java.util.concurrent.Executor DUAL_THREAD_EXECUTOR
| 构造方法详细信息 |
|---|
public AsyncTask()
| 方法详细信息 |
|---|
public static void init()
public static void setDefaultExecutor(java.util.concurrent.Executor exec)
public final AsyncTask.Status getStatus()
public final boolean isCancelled()
cancel(boolean) on the task,
the value returned by this method should be checked periodically from
doInBackground(Object[]) to end the task as soon as possible.
cancel(boolean)public final boolean cancel(boolean mayInterruptIfRunning)
Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.
Calling this method will result in onCancelled(Object) being
invoked on the UI thread after doInBackground(Object[])
returns. Calling this method guarantees that onPostExecute(Object)
is never invoked. After invoking this method, you should check the
value returned by isCancelled() periodically from
doInBackground(Object[]) to finish the task as early as
possible.
mayInterruptIfRunning - true if the thread executing this
task should be interrupted; otherwise, in-progress tasks are allowed
to complete.
isCancelled(),
onCancelled(Object)
public final Result get()
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException
java.util.concurrent.CancellationException - If the computation was cancelled.
java.util.concurrent.ExecutionException - If the computation threw an exception.
java.lang.InterruptedException - If the current thread was interrupted
while waiting.
public final Result get(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException,
java.util.concurrent.ExecutionException,
java.util.concurrent.TimeoutException
timeout - Time to wait before cancelling the operation.unit - The time unit for the timeout.
java.util.concurrent.CancellationException - If the computation was cancelled.
java.util.concurrent.ExecutionException - If the computation threw an exception.
java.lang.InterruptedException - If the current thread was interrupted
while waiting.
java.util.concurrent.TimeoutException - If the wait timed out.public final AsyncTask<Params,Progress,Result> execute(Params... params)
Note: this function schedules the task on a queue for a single background
thread or pool of threads depending on the platform version. When first
introduced, AsyncTasks were executed serially on a single background thread.
Starting with android.os.Build.VERSION_CODES#DONUT, this was changed
to a pool of threads allowing multiple tasks to operate in parallel. Starting
android.os.Build.VERSION_CODES#HONEYCOMB, tasks are back to being
executed on a single thread to avoid common application errors caused
by parallel execution. If you truly want parallel execution, you can use
the executeOnExecutor(java.util.concurrent.Executor, Params...) version of this method
with THREAD_POOL_EXECUTOR; however, see commentary there for warnings
on its use.
This method must be invoked on the UI thread.
params - The parameters of the task.
java.lang.IllegalStateException - If getStatus() returns either
AsyncTask.Status.RUNNING or AsyncTask.Status.FINISHED.executeOnExecutor(java.util.concurrent.Executor, Object[]),
execute(Runnable)
public final AsyncTask<Params,Progress,Result> executeOnExecutor(java.util.concurrent.Executor exec,
Params... params)
This method is typically used with THREAD_POOL_EXECUTOR to
allow multiple tasks to run in parallel on a pool of threads managed by
AsyncTask, however you can also use your own Executor for custom
behavior.
Warning: Allowing multiple tasks to run in parallel from
a thread pool is generally not what one wants, because the order
of their operation is not defined. For example, if these tasks are used
to modify any state in common (such as writing a file due to a button click),
there are no guarantees on the order of the modifications.
Without careful work it is possible in rare cases for the newer version
of the data to be over-written by an older one, leading to obscure data
loss and stability issues. Such changes are best
executed in serial; to guarantee such work is serialized regardless of
platform version you can use this function with SERIAL_EXECUTOR.
This method must be invoked on the UI thread.
exec - The executor to use. THREAD_POOL_EXECUTOR is available as a
convenient process-wide thread pool for tasks that are loosely coupled.params - The parameters of the task.
java.lang.IllegalStateException - If getStatus() returns either
AsyncTask.Status.RUNNING or AsyncTask.Status.FINISHED.execute(Object[])public static void execute(java.lang.Runnable runnable)
execute(Object...) for use with
a simple Runnable object. See execute(Object[]) for more
information on the order of execution.
execute(Object[]),
executeOnExecutor(java.util.concurrent.Executor, Object[])
|
||||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||