You could use a LinkedBlockingDeque and physically remove the item from the queue (using takeLast()
) but replace it again at the end of the queue if processing fails using putLast(E e)
. Meanwhile your “producers” would add elements to the front of the queue using putFirst(E e)
.
You could always encapsulate this behaviour within your own Queue
implementation and provide a blockingPeek()
method that performs takeLast()
followed by putLast()
behind the scenes on the underlying LinkedBlockingDeque
. Hence from the calling client’s perspective the element is never removed from your queue.