Queue队列实例
import java.util.Queue;
import java.util.LinkedList;
import com.cs.webTool.bean.UserData;
public class Dee {
public static void main(String[] args) {
Dee.namer();
}
public static void name() {
Queue<String> queue = new LinkedList<String>();
queue.offer("hello!");
queue.offer("World!");
queue.offer("你好!");
queue.offer("wowowo");
System.out.println(queue.size());
String str;
while((str=queue.poll())!=null){
System.out.print(str);
}
System.out.println();
System.out.println(queue.size());
}
public static void namer() {
UserData userData = new UserData();
userData.setWaterNum("1");
UserData userData1 = new UserData();
userData1.setWaterNum("1---");
Queue<UserData> queue = new LinkedList<UserData>();
queue.offer(userData);
queue.offer(userData1);
//System.out.println(queue.size());
UserData str;
while((str=queue.poll())!=null){
System.out.println(str.getWaterNum());
}
// System.out.println();
System.out.println(queue.size());
}
}
package com.cs.webTool.action;
import java.util.LinkedList;
import java.util.Queue;
import com.cs.webTool.bean.SubmitInfo;
/**
*
* @author zhf
* 单例模式 服务启动后 quue此对象(队列)不变
*/
public class MyQueue {
public static Queue<SubmitInfo> queue = null;
private static MyQueue instance = null;
private MyQueue() {
queue = new LinkedList<SubmitInfo>();
}
public synchronized static MyQueue getInstance() {
if (instance == null) {
instance = new MyQueue();
}
return instance;
}
}
//将SubmitInfo对象放入queue中(队列中)
MyQueue aMyQueue = MyQueue.getInstance();
aMyQueue.queue.offer(submitInfo);