📄 queue.java
字号:
package com.sf.note;
import java.util.LinkedList;
public class Queue {
LinkedList list = new LinkedList();
private final int MaxQueueSize = 2000;
private int discardMsg = 0;
public Queue() {
}
@SuppressWarnings("unchecked")
public synchronized void put(Object msg) throws InterruptedException {
if (MaxQueueSize <= this.getQueueSize()) {
discardMsg++;
return;
}
if (msg == null) {
return;
}
list.add(msg);
this.notifyAll();
}
@SuppressWarnings("unchecked")
public synchronized void put(Object msg, int flag)
throws InterruptedException {
if (MaxQueueSize <= this.getQueueSize()) {
discardMsg++;
return;
}
if (msg == null) {
return;
}
list.add(msg);
this.notifyAll();
}
@SuppressWarnings("unchecked")
public synchronized void putFirst(Object msg) throws InterruptedException {
if (MaxQueueSize <= this.getQueueSize()) {
return;
}
if (msg == null) {
return;
}
list.addFirst(msg);
this.notifyAll();
}
public synchronized Object get() throws InterruptedException {
while (list.isEmpty()) {
try {
this.wait();
} catch (InterruptedException e) {
}
}
return list.removeFirst();
}
public boolean isEmpty() {
return list.isEmpty();
}
public int getQueueSize() {
return list.size();
}
public int getDiscardMsg() {
return discardMsg;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -