Consider the following situation:
- You have a program which creates numerous 'jobs' that need to be processed and places them into a queue.
- You have other worker programs which grab the next 'job' in line so they can process that job.
- Each job has a category.
- There could be any number of categories.
- Two jobs that have the same category cannot be processed at the same time by separate workers.
- A worker can process one job at a time.
A traditional queue would not work in this situation because there is a chance that multiple jobs of the same category would be processed simultaneously, which is not allowed.
You could have the worker check the job it grabs and see if that jobs category has another worker that is currently processing against it, and if so re-submit the job into the queue to be processed at a later time. This seems like an inefficient way of solving this problem. Are there any data structures or design patterns that can solve this issue?
If you need further clarification, please let me know.