轻量级、可折叠的 Executor 实现?
我正在构建一个 Android 移动应用程序,我需要为每个列表适配器汇集 HTTP 请求。我基本上想要一个“崩溃”的 ExecutorService 实现,即:它将使用最多 n 个线程,但当线程完成时,它们将立即过期,从而使其真正轻量级。如果需求很高,它只会将任务转储到队列中,等待线程变得可用。有没有办法在不自己编写 ExecutorService 的情况下做到这一点,或者我应该亲自动手去做呢?
I'm building a mobile app for Android and I need to pool HTTP requests for each of my List adapters. I basically want an ExecutorService
implementation that "collapses," ie: it will use up to n threads, but as threads complete, they will immediately expire, making it really lightweight. If there's high demand, it'll just dump tasks into a queue which will wait for threads to become available. Is there a way to do this without writing an ExecutorService
myself or should I just get my hands dirty and do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ThreadPoolExecutor
及其keepAliveTime
设置为零?例如,
来自
setKeepAliveTime()
的文档:Would it work to use a
ThreadPoolExecutor
with itskeepAliveTime
set to zero?e.g.
From the docs for
setKeepAliveTime()
: