There will be times when the producer will be lagging behind and the consumer will find no available entries to poll OR the opposite when the consumer will be lagging behind and the producer will encounter a full queue. For these situations you want to use of a waiting strategy that combines busy spinning, thread yielding and sleeping to accomplish the best performance under your particular CPU architecture. Below you can see the version of the sample code with a wait strategy for the producer and another different one for the consumer:
Failed to load source code from svn: http://soliveirajr.com/svn/mentaqueue/trunk/src/main/java/org/mentaqueue/test/sample/SampleCodeWithWaitStrategy.java