Let all threads have their own queue. You might implement a new thread like MainThread
or DispatcherThread
which takes objects from your LinkedBlockingQueue
and decides which WorkerThread
to process it. Something like :
private void decideQueue(String objectId) { // actually decides which thread to process it.
Queue queue = getQueueIfObjectIdPreviouslyUsed(objectId);
if (queue == null) {
queue = getNextAvailableQueue();
}
queue.enqueue();
//..
//don't forget to dequeue from the main queue
//..
}
To decide whether an onjectId is previously processed or not you might use a Map
that keeps objectId as key and associated Queue
as value. And you do the necessary work in getQueueIfObjectIdPreviouslyUsed
method.