The other requirement of the design was to select jobs for execution based on priority and to change the priority of the jobs in the runtime. For the former task we could use the Priority Queue implementation. The latter task was challanging since that Priority Queue implementation had only two methods - Enqueue and Dequeue. So there was no possibility to look through the Queue to change the priority of the item. To solve this problem I used the following strategy:
- A wrapper class was provided for the job, which was identified by a unique ID
- The user could use the ID of the job to indicate that the priority for this job should be changed
- The Thread Pool class used an internal job ID and a mapping from the user's ID to the internal one
- The Priority Queue contained the internal job IDs
- When the user wanted to change the priority of the job the following iterations took place:
- New internal ID for the job was created and sent to the Priority Queue
- Mapping from the user's ID to the internal one was updated
- The system remembered that the old internal ID is not valid any more and should not be processed when it will be
dequeued
http://www.linkedin.com/in/oldbam
No comments:
Post a Comment