开发者

Download Manager with priority (Java, Android)

开发者 https://www.devze.com 2023-04-09 18:26 出处:网络
I\'m d开发者_StackOverflow社区oing a little download manager within my app. I was using ThreadPoolExecutor threadpool = new ThreadPoolExecutor(1,210, (int) 210, TimeUnit.SECONDS,new ArrayBlockingQue

I'm d开发者_StackOverflow社区oing a little download manager within my app. I was using

ThreadPoolExecutor threadpool = new ThreadPoolExecutor(1,210, (int) 210, TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(210), new mThreadFactory());

and calling the following method for order the downloads:

threadpool.execute( new DownloadRunnable(url) );

Recently I changed a little my app and now I need to distinguish two kinds of downloads: Foreground Downloads (for elements that need to be shown to the user asap) and Background Downloads for saving a Internet resource at the disk for example.

I want some kind of pool executor always when picking the new element for download priorize Foreground downloads if exists and else download a background resource.

Can someone guide me with that solution?

Thanks in advance


You can use a PriorityBlockingQueue instead of your ArrayBlockingQueue and give the foreground downloads a higher priority.

0

精彩评论

暂无评论...
验证码 换一张
取 消