AsyncTask 不会终止
我启动了一个AsyncTask
。一切似乎都正常,我检查了 doInBackground
中是否已完成任务。 onPostExecute
也会被调用。 问题是我一直在 Eclipse 的线程列表中看到我的 AsyncTask
,如果我再次开始,我会看到第二个副本。
线程不应该在 onPostExecute()
结束时终止吗? 我还发现了这个关于同一问题的线程。
但它并没有给出明确的答案。
谢谢
I started an AsyncTask
. Every seems to be OK and I checked that I get to the end of the task in doInBackground
. onPostExecute
is called too.
The problem is that I keep seeing in the list of the thread in Eclipse my AsyncTask
and if I started again I see a second copy.
Shouldn't the thread be termintated at the end of onPostExecute()
?
I have also found this thread about the same problem.
It does not give a definitive answer though.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
鉴于您实际上没有做错什么,
Thread
的存在并不意味着有任何事情一定是错误的。AsyncTask
使用内部线程池,并且可以保留线程以供将来使用,而无需创建和调用线程的开销。所以完全有可能一切都很好。Given that you haven't actually done something wrong, the presence of the
Thread
doesn't signal that anything is necessarily wrong. TheAsyncTask
uses an internal thread pool and the threads can be kept around for further future use without the overhead of Thread creation and invocations. So it's entirely possible that everything is just fine.