Таким образом, после ряда решений (пользовательская очередь, отдельная изменяемая переменная для отслеживания вставки) это оказалось очень простым решением с использованием метода offer
:
/**
* Inserts the specified element into this queue, if another thread is
* waiting to receive it.
*
* @param e the element to add
* @return {@code true} if the element was added to this queue, else
* {@code false}
* @throws NullPointerException if the specified element is null
*/
public boolean offer(E e) {
if (e == null) throw new NullPointerException();
return transferer.transfer(e, true, 0) != null;
}
Если я просто сделаю if(offer(e)) ... else ...
, это поможетразблокировать потребителя, если есть.