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 add non-blocking behaviour to an ArrayBlockingQueue
by surrounding it with a conditional offer()
statement, where failure of the queue to accept the offer results in the head being dropped and the offer being re-made:
public class LearnToQueue {
public static void main(String[] args){
Queue FIFO = new ArrayBlockingQueue(4);
int i = 0;
while ( i < 10 ){
if (!FIFO.offer(i)){
// You can pipe the head of the queue anywhere you want to
FIFO.remove();
FIFO.offer(i);
}
System.out.println(FIFO.toString());
i++;
}
}
}