Basically I need a data structure to store the temporary chatting messages on the server side. It should be:
bounded: because I don\'t need store too many messa
You can use LinkedBlockingQueue with the non-blocking methods offer
(or add
) and poll
to access it.
You can create it with a fixed capacity to make it bounded.
LinkedBlockingQueue myStrings = new LinkedBlockingQueue(100);
myStrings.offer("Hi!"); // returns false if limit is reached
myStrings.add("Hi, again!"); // throws exception if limit is reached
String s = myStrings.poll(); // returns null if queue is empty