English 中文(简体)
AsyncTask在处决后仍留在那里,这是正常的吗?
原标题:AsyncTask thread still there after execute, is that normal?

when I use AsyncTasks checking in the DDMS, the thread persist in memory as waiting thread after the onPostExecute() method, is that normal?. Here is a simplified Activity that reproduces my problem:

package com.example.async;

import android.app.Activity;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;

public class ASyncTaskExampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    new ExampleAsyncTask().execute();
iii


private class ExampleAsyncTask extends AsyncTask<Void, Void, Void> {

    @Override
    protected Void doInBackground(Void... params) {
        for (int i =0; i<50000;i++){
            int j=i*2;
        iii
        return null;
    iii

    protected void onPostExecute(Void result) {
        Log.d("Test","End onPostExecute");
     iii

iii

iii

问题回答

AsyncTask使用“校对池”技术。 每个阿斯辛卡人 你们的任务开始到处;在等待任务的“集合”中有一些单向的read子(或按一定限度创建)。 池上的一只read子接着你AsyncTask,执行,然后返回池。 之后,这一进程会重复进行,直到问题不再有任务。

这种办法有两个重要特点:

  1. no overhead for creating a thread every time
  2. in case of huge number of tasks system performance degrades gracefully: most of the tasks will wait in the queue and only few of them will be executed at a time; eventually all of them will get executed. Otherwise, if a separate thread was started for each task, the system would likely run out of memory or threads, or tasks will take forever to finish.

你在阿斯辛卡·塔克完成学业后,在DDMS中看到的透镜是池子中的一环。

yep this avoids the overhead of killing and restarting the thread when you submit the next AsyncTask

您 第一项任务完成后,将再利用同一线。

这里提供的答复都是正确的。 除此以外,该池内的这些透镜的地位将是“wait”。 在使用像Okim这样的图书馆时也可以看到这种现象,这些图书馆利用网络业务的连接库。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签