I'm implementing a Java App which performs parallel processing: When my app starts, the 4 threads that belong to a Thread Pool are created. Then, I start receiving objects that are added to a LinkedBlockingQueue. Each object has an ID, and depending on the ID, a pre-defined task is performed. My "Queue Consumers" are those 4 Threads that were initialized, and they begin to take the objects out of the queue, and perform the tasks that corresponds to each object.
It is possible to define in which Thread each object will be processed? I want to "schedule tasks to each Thread".
For example:
- When the first object is taken from the queue, he will be processed by Thread1.
- If the second object as a different ID than the first one, it will be processed by Thread2.
- If the third object has the same ID than the first object that was taken, it will "go to Thread1".
How can I implement this?
Thanks