命名 AsyncTask 的线程
是否可以为 AsyncTask 的后台线程指定一个名称,就像 Java 中的普通线程一样:
Thread(Runnable target, String name)
我看过 AsyncTask 的代码,默认构造函数只是默认指定一个名称
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
public Thread newThread(Runnable r) {
return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
}
};
我想这样做,因为当我调试时我想要了解哪个 Asynctask 正在访问帮助程序类中的方法。
Is it possible to give a name to an AsyncTask's background thread, as for normal Threads in Java:
Thread(Runnable target, String name)
I have seen the code of AsyncTask and the default constructor is just give a name by default
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
public Thread newThread(Runnable r) {
return new Thread(r, "AsyncTask #" + mCount.getAndIncrement());
}
};
I want to do that, as when I debug I want to know which Asynctask is accessing a method in a helper class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从
doInBackground()
内部调用它:Try calling this from inside
doInBackground()
:为什么你不能扩展 AsyncTask 我不明白。
我用调试器将我的 AsyncTask 扩展了数千次,向我展示了哪个 AsyncTask 正在抱怨。
像这样
Why can't you extend the AsyncTask I dont understand.
I extend my AsyncTask thousand times with debugger shows me which AsyncTask is bitching.
like so