title: Java bounded non-blocking buffer for high concurrent situation
body: <p>Basically I need a data structure to store the temporary chatting messages on the server side. It should be:</p>
  
  <ul>
  <li><p>bounded: because I don't need store too many messages, the client will send request to get the new messages every second. I think the bound size should be the max. mount of concurrent requests in one second. When the buffer is full, the old messages will be removed.</p></li>
  <li><p>suitable for high concurrent access: I don't want to use the data structure like Collections.synchronizedXXXX, because during the iteration, if other thread changes the data structure, e.g. adds a message, it will throw an Exception, so I have to lock the whole data structure, actually I don't really care if the client request can get the most last inserted message, because they will send a new request after one second, on the other side the write operation should be never delayed. The classes under the package java.util.concurrency seems the solution, but...</p></li>
  <li><p>non-blocking: LinkedBlockingQueue, ArrayBlockingQueue they could be bounded and won't throw exception during iteration, but they are all blocking queue. When the queue is full, I want to add the new element to the tails and remove the old element from head instead of blocking there and wait for someone to remove the header.</p></li>
  </ul>
  
  <p>So my question is there any good implementation from 3rd library? For example Google Guava?
  Or maybe you have better idea about storing the temporary chatting messages on server?</p>
  
  <p>thank you very much!</p>