使用线程池和调度程序 优先队列?
我将使用线程池和线程池来实现调度程序。 Java中的优先级队列,我想问是否有人知道任何现有的实现,所以我没有花时间在它上面:-)...
基本上,java.util.concurrent包中的ScheduledThreadPoolExecutor提供了几乎我需要的功能除了“优先队列”。 当我粗略地检查了内置的java库时,我找不到任何支持修改&的优先级队列。 在将元素放入队列后,从外部更新元素的“优先级”值。
我需要在类似下载器的项目中使用这种优先级队列。 我希望允许用户即时修改每个下载的优先级,并且其在队列中的位置会自动更新。 PriorityQueue 不是以这种方式实现的,为了获得正确的优先级,每次我们更改其优先级值时,我们都必须删除 & 。 再次提交...
之前有人做过这方面的工作吗?
I'm gonna implement a scheduler using thread pool & priority queue in Java and I want to ask whether anybody knows any existing implementations or not, so I don't have spend time on it :-)...
Basically, the ScheduledThreadPoolExecutor in java.util.concurrent package provides almost functions I need except the "priority queue". As I roughly checked the built-in java libraries, I couldn't find any priority queue which supports modifying & updating "priority" value of an element externally after it has been put to the queue.
I need this kind of priority queue to be used in a downloader-liked project. I want to allow users to modify the priority of each download on-the-fly and its position in the queue is automatically updated. The PriorityQueue is not implemented in this way, in order to get correct priority, each time we change its priority value we have to remove & submit it again...
Did anybody work on this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以检查 PriorityQueue 或 < a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/PriorityBlockingQueue.html" rel="nofollow noreferrer">PriorityBlockingQueue。 我认为它们都不允许您修改优先级。 但您始终可以删除某个元素,然后以修改后的优先级将其添加回来。
You can check PriorityQueue or PriorityBlockingQueue. I don't think either of them allow you to modify the priority. But you can always remove an element and add it back with modified priority.
您可以使用Quartz,它是一个功能齐全的调度程序并支持优先级
You can use Quartz, it is a fully functional scheduler and supports priorities