使用的ThreadPoolExecutor和AsyncTask的 [英] Using ThreadPoolExecutor and AsyncTask

查看:307
本文介绍了使用的ThreadPoolExecutor和AsyncTask的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用的ThreadPoolExecutor我可以在我的队列中使用的AsyncTask作为Runnable的?还是这个击败目的是什么?

  //一个用于各种任务持有人
私人最终的LinkedBlockingQueue<&的Runnable GT;队列=新的LinkedBlockingQueue<&的Runnable GT;(5);//线程池的Executor
私人最终的ThreadPoolExecutor TPE =新的ThreadPoolExecutor(3,3,10,TimeUnit.SECONDS,队列);


解决方案

这是AsyncTask的是不是一个Runnable,所以你不能真正使用。

When using ThreadPoolExecutor can I use AsyncTask as the Runnable in my queue? Or does this defeat the purpose?

//A holder for various tasks
private final LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(5);

//Thread Pool Executor
private final ThreadPoolExecutor tpe = new ThreadPoolExecutor(3, 3, 10, TimeUnit.SECONDS, queue);

解决方案

An AsyncTask is not a Runnable so you can't really use that.

这篇关于使用的ThreadPoolExecutor和AsyncTask的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆