package org.apache.tomcat.util.collections;
public class SynchronizedQueue<T> {
public static final int DEFAULT_SIZE = 128;
private Object[] queue;
private int size;
private int insert;
private int remove;
public SynchronizedQueue() {
this(128);
}
public SynchronizedQueue(int initialSize) {
this.insert = 0;
this.remove = 0;
this.queue = new Object[initialSize];
this.size = initialSize;
}
public synchronized boolean offer(T t) {
this.queue[this.insert++] = t;
if (this.insert == this.size) {
this.insert = 0;
}
if (this.insert == this.remove) {
this.expand();
}
return true;
}
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??