标签:boolean nbsp str link col 自带 oid ati org
package com.csf.myproject.core; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import org.apache.log4j.Logger; public class QueueFile { // 上传信息 private static final Logger logger = Logger.getLogger(QueueFile.class); // 快照行情 private static BlockingQueue<String> queue = new LinkedBlockingQueue<String>(); private static boolean isEOF = false; public static int count = 0; public static int getCount(){ return count; } // 放入行情 public static void produce(String message) { try { count ++; queue.put(message); } catch (Exception e) { logger.error(e, e); } } // 消费行情 public static String consume() { try { return queue.take(); } catch (Exception e) { logger.error(e, e); } return null; } // 行情队列是否为空 public static boolean isEmpty() { return (queue.isEmpty() && isEOF); } // 关闭队列 public static void close() { QueueFile.isEOF = true; } public static void main(String[] args) { QueueFile.produce("hello"); QueueFile.produce("hell2o"); QueueFile.produce("hell2o"); for( int i = 0 ; i <= QueueFile.getCount();i ++){ String consume = QueueFile.consume(); System.out.println(consume); } } // 方式二 队列消费 public static void main2(String[] args){ Queue<String> queue = new ConcurrentLinkedQueue<>(); int count = 0; queue.add("马风雷"); queue.add("当前的测试文件"); queue.add("马上消费"); count = 3; for(int i= 0;i< count;i++ ){ String mes = queue.poll(); System.out.println(mes); } } }
标签:boolean nbsp str link col 自带 oid ati org
原文地址:http://www.cnblogs.com/xiaolei2017/p/7908492.html