shz.core.queue.l.ConcurrentLinkedQueue Maven / Gradle / Ivy
package shz.core.queue.l;
import shz.core.lock.ReadWriteLockHolder;
import shz.core.node.SNode;
import java.io.Serializable;
import java.util.NoSuchElementException;
/**
* 基于链表的队列
*/
public abstract class ConcurrentLinkedQueue> extends ReadWriteLockHolder implements Serializable {
private static final long serialVersionUID = 4223481645384749598L;
protected T tail, head;
protected int size;
public final int size() {
readLock.lock();
try {
return size;
} finally {
readLock.unlock();
}
}
public final boolean isEmpty() {
readLock.lock();
try {
return head == null;
} finally {
readLock.unlock();
}
}
public final void clear() {
writeLock.lock();
try {
tail = head = null;
size = 0;
} finally {
writeLock.unlock();
}
}
protected final void checkEmpty() {
if (head == null) throw new NoSuchElementException();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy