我这样写消息队列为什么错,代码是。。。 建议用LinkedList做消息队列,不要用数组。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 建议用vector作队列可以这样:public class Queue extends java.util.Vector { public Queue() { super(); } public synchronized void enq(Object x) { super.addElement(x); } public synchronized Object deq() { /* 队列若为空,引发EmptyQueueException异常 */ if( this.empty() ) throw new EmptyQueueException(); Object x = super.elementAt(0); super.removeElementAt(0); return x; } public synchronized Object front() { if( this.empty() ) throw new EmptyQueueException(); return super.elementAt(0); } public boolean empty() { return super.isEmpty(); } public synchronized void clear() { super.removeAllElements(); } public int search(Object x) { return super.indexOf(x); } } public class EmptyQueueException extends java.lang.RuntimeException { public EmptyQueueException() { super(); } } hibernate使用oracle序列 swing 组件,事件,监听器关系 怎样用java抽取html的链接和链接的文本,谢谢 [问]关于String java类的使用问题,大家看看我的代码, 在jbuilder环境下运行一切正常,在字符截面下就出现这种情况,为何 drawString时怎样规定显示区域?? 一个傻傻的问题,千万不要见笑 HttpURLConnection的详细用法 JDBC有没有只返回某一字段排在前面的几条记录的功能 关于文件系统路径! 文件流问题?
可以这样:public class Queue extends java.util.Vector {
public Queue() {
super();
}
public synchronized void enq(Object x) {
super.addElement(x);
}
public synchronized Object deq() {
/* 队列若为空,引发EmptyQueueException异常 */
if( this.empty() )
throw new EmptyQueueException();
Object x = super.elementAt(0);
super.removeElementAt(0);
return x;
}
public synchronized Object front() {
if( this.empty() )
throw new EmptyQueueException();
return super.elementAt(0);
}
public boolean empty() {
return super.isEmpty();
}
public synchronized void clear() {
super.removeAllElements();
}
public int search(Object x) {
return super.indexOf(x);
}
} public class EmptyQueueException extends java.lang.RuntimeException {
public EmptyQueueException() {
super();
}
}