Tracking the progress between Queues in a Map : <p>I have currently two queues and items traveling between them. Initially, an item gets put into <code>firstQueue</code>, then one of three dedicated thread moves it to <code>secondQueue</code> and finally another dedicated thread removes it. These moves obviously include some processing. I need to be able to get the status of any item (<code>IN_FIRST</code>, <code>AFTER_FIRST</code>, <code>IN_SECOND</code>, <code>AFTER_SECOND</code>, or <code>ABSENT</code>) and I implemented it manually by doing the update of the <code>statusMap</code> where the queue gets modified like</p>

<pre><code>while (true) {
    Item i = firstQueue.take();
    statusMap.put(i, AFTER_FIRST);
    process(i);
    secondQueue.add(i);
    statusMap.put(i, IN_SECOND);
}
</code></pre>

<p>This works, but it's ugly and leaves a time window where the status is inconsistent. The inconsistency is no big deal and it'd solvable by synchronization, but this could backfire as the queue is of limited capacity and may block. The ugliness bothers me more.</p>

<p>Efficiency hardly matters as the processing takes seconds. Dedicated threads are used in order to control concurrency. No item should ever be in multiple states (but this is not very important and not guaranteed by my current racy approach). There'll be more queues (and states) and they'll of different kinds (<code>DelayQueue</code>, <code>ArrayBlockingQueue</code>, and maybe <code>PriorityQueue</code>).</p>

<p><em>I wonder if there's a nice solution generalizable to multiple queues?</em></p>
