Monday, April 25, 2011

Scheduler using Thread Pool & Priority Queue?

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?

From stackoverflow
  • 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.

  • You can use Quartz, it is a fully functional scheduler and supports priorities

    instcode : Yes, I know Quartz but I don't want to carry a big guy in my distribution just for a small function. Moreover, the problem's still there because Quartz doesn't support updating "priority" on the fly... I guess I should save our time by using what ScheduledThreadPoolExecutor supports :-)

0 comments:

Post a Comment