Executor Service with LIFO ordering

后端 未结 4 767
不知归路
不知归路 2020-12-24 09:43

I wrote a lazy image downloader for my app using an ExecutorService. It gives me great control about how many downloads are running in parallel at what time and so on.

4条回答
  •  清歌不尽
    2020-12-24 09:57

    The ThreadPoolExecutor has a constructor which allows to specify the queue type to use. You can plug any BlockingQueue in there, and possibly a priority queue might be a good fit for you. You can configure the priority queue to sort based on a (creation) time stamp which you add to you download jobs, and the executor will execute the jobs in the desired order.

提交回复
热议问题