The brief description of java.util.concurrent.LinkedBlockingQueue says it is a FIFO queue, which means if thread A adds a bunch of entries (a1, a2, ... an) into the queue first and then thread B adds some more stuff into the queue (b1, b2, ... bm), then some consumer threads should exhaust all entries from A before taking on these from B (thus FIFO). But what I have seen is that the entries from A and these from B are interleaved even though B adds its entries much later than A. I was at a code review for some Tomcat + Jersey application, and it uses a singleton LinkedBlockingQueue
plus a handful of asynchronous worker threads to process the request entries from clients.
I was questioning about the fairness of the code since late arriving requests would have to wait in the queue until earlier entries are all exhausted (a client can submit thousands of entries per request), but to my surprise, the late arrival clients got their responses back almost immediately. So does this mean LinkedBlockingQueue
is not FIFO?? Please help for I am very confused.