了解异步任务
AsyncTask 调用完成后,线程是否会被删除?
我将 AsyncTask 存储在 var“guiThread = (GUIAsyncTask) new GUIAsyncTask()”中。 对execute() 的第一次调用有效,但后续调用无效。 那么,我是否可以在需要时创建新任务?我的印象是,我一遍又一遍地使用我的变量,一遍又一遍地调用 new 会启动数千/数百万个线程。
Once an AsyncTask call is finished is the thread deleted?
I stored an AsyncTask in a var "guiThread = (GUIAsyncTask) new GUIAsyncTask()".
The first call to execute() works but subsequent calls don't.
So, do I just create new tasks whenever I need them? I was under the impression that I used my variable over and over and calling new over and over would spin up thousands/millions of threads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AsyncTasks
是一次性使用的。他们开始,执行,然后死亡。然后,您可以选择保留引用以从中收集可能存储在执行后的类中的信息,或者转储引用并让垃圾收集器处理它。如果你想再次启动AsyncTask
,你必须创建一个新对象并启动它。AsyncTasks
are one-time uses. They start, execute, then die. Then you have a choice of keeping the reference around to gather information from it that may be stored in the class post-execute, or dumping the reference and letting the garbage collector handle it. If you want to start theAsyncTask
again, you have to create a new object and start it.不,您每次想要使用它时都需要创建一个新的 AyncTask。
Nope you need to create a new AyncTask everytime you want to use it.
AsyncTask 在使用时必须创建
An AsyncTask must be created any time it is to be used