Java(Android)中的优先ThreadPoolExecutor

Java(Android)中的优先ThreadPoolExecutor,第1张

Java(Android)中的优先ThreadPoolExecutor

ThreadPoolExecutor
构造函数接受
BlockingQueue<Runnable>
而不是
BlockingQueue<? extendsRunnable>
,因此您不能传递给它的
PriorityBlockingQueue<mDownloadThread>
实例。

您可以将的类型更改

queue
PriorityBlockingQueue<Runnable>
,但是在这种情况下,如果不将其
Comparator<mDownloadThread>
强制转换为
compare
方法,就无法实现。

另一种解决方案是绕过泛型类型检查,但是这将是你的责任,只提交的情况下

mDownloadThread
,以
execute
方法:

static ThreadPoolExecutor threadpool = new ThreadPoolExecutor(30, MAXPOOL,         MAXPOOL, TimeUnit.SECONDS, (PriorityBlockingQueue) queue, new mThreadFactory());


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5430268.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存