package org.apache.tomcat.util.collections;

public class SynchronizedQueue<T&gt; {
&nbsp; &nbsp; public static final int DEFAULT_SIZE = 128;
&nbsp; &nbsp; private Object[] queue;
&nbsp; &nbsp; private int size;
&nbsp; &nbsp; private int insert;
&nbsp; &nbsp; private int remove;


&nbsp; &nbsp; public SynchronizedQueue() {
&nbsp; &nbsp; &nbsp; &nbsp; this(128);
&nbsp; &nbsp; }


&nbsp; &nbsp; public SynchronizedQueue(int initialSize) {
&nbsp; &nbsp; &nbsp; &nbsp; this.insert = 0;
&nbsp; &nbsp; &nbsp; &nbsp; this.remove = 0;
&nbsp; &nbsp; &nbsp; &nbsp; this.queue = new Object[initialSize];
&nbsp; &nbsp; &nbsp; &nbsp; this.size = initialSize;
&nbsp; &nbsp; }


&nbsp; &nbsp; public synchronized boolean offer(T t) {
&nbsp; &nbsp; &nbsp; &nbsp; this.queue[this.insert++] = t;
&nbsp; &nbsp; &nbsp; &nbsp; if (this.insert == this.size) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.insert = 0;
&nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; if (this.insert == this.remove) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.expand();
&nbsp; &nbsp; &nbsp; &nbsp; }


&nbsp; &nbsp; &nbsp; &nbsp; return true;
&nbsp; &nbsp; }

I think that when insert = = remove, the contents of the queue should be empty. 
When multiple pollerevents are produced and not consumed, the capacity needs to 
be expanded
so I think the code in the red part should exchange positions??

Reply via email to