import java.util.Stack; import org.apache.log4j.Logger; import com.ctis.ta.util.PropertiesUtils; /** * java 栈队列 * @author * */ public class ActiveQueue { public static Logger log = Logger.getLogger(ActiveQueue.class); private static Stack _queue; private static ActiveQueue activeQueue; //private final static int QUEUE_SIZE = 100; private final static int QUEUE_SIZE = PropertiesUtils.getQueueSizeNum(); private ActiveQueue() { } public static ActiveQueue getInstance(){ if(null==_queue){ _queue = new Stack(); activeQueue = new ActiveQueue(); } return activeQueue; } public synchronized int enqueue() { while(_queue.size() >= QUEUE_SIZE) { try { wait(2000); }catch (InterruptedException e) { log.error(this, e); } } _queue.push(new Object()); notifyAll(); log.info("enqueue-->"+_queue.size()); log.info("QUEUE_SIZE-->"+QUEUE_SIZE); return 1; } public synchronized void dequeue() { while(_queue.empty()) { try { wait(); }catch (InterruptedException e) { log.error(this, e); } } _queue.pop(); notifyAll(); log.info("dequeue-->"+_queue.size()); } }
栈队列
猜你喜欢
转载自love398146779.iteye.com/blog/2046131
今日推荐
周排行