I have not coded in Java for a few years so it might be good to get another opinion, though some points did stand out while reading your code.
It seems odd to me that you would use an
ArrayList
with a fixed size, personally I would just use an array for the buffer.when you dequeue, you do not overwrite the value until you enqueue over the top of it. This might not seem like an issue (and if you only queue primative types like
int
, its not) but if you use valuereference types and the queue cycles slowly then it means you hold a reference to the object for longer than needed and it cannot be collected.I'm a bit worried about catching the
InterruptedException
inside a while(true) loops without breaking out of the loop. The most common reason I have seen for one thread to interrupt another is when the interrupting thread wants to give the interrupted thread the opportunity to terminate gratefully, but this will prevent that option. I thought about what can be returned in such a case and eventually decided it might be best to let this exception flow through and be handled by the caller.