| | |
| | | import org.apache.logging.log4j.Logger; |
| | | |
| | | /** |
| | | * 队列,先进先出 |
| | | * 队列,先进先出,非线程安全 |
| | | */ |
| | | public class Queue { |
| | | @SuppressWarnings("unfinal") |
| | |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public void pushHead(NodeObj obj)throws Exception{ |
| | | //两个线程环境,需要同步锁 |
| | | synchronized(synObj){ |
| | | if(obj == null){ |
| | | return ; |
| | |
| | | * @param obj 入列的对象 |
| | | */ |
| | | public void pushTail(NodeObj obj)throws Exception{ |
| | | //两个线程环境,需要同步锁 |
| | | synchronized(synObj){ |
| | | if(obj == null){ |
| | | return ; |
| | |
| | | * @return 出列对象 |
| | | */ |
| | | public NodeObj pop(){ |
| | | //两个线程环境,需要同步锁 |
| | | synchronized(synObj){ |
| | | NodeObj obj = null ; |
| | | if(this.size > 0){ |
| | |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public Node getFirstNode(){ |
| | | Node node = this.head.next ; |
| | | if(node != this.tail){ |
| | | return node ; |
| | | //两个线程环境,需要同步锁 |
| | | synchronized(synObj) { |
| | | Node node = this.head.next; |
| | | if (node != this.tail) { |
| | | return node; |
| | | } |
| | | return null; |
| | | } |
| | | return null ; |
| | | } |
| | | /** |
| | | * 得到最后一个节点,但不把节点从队列中清除 |
| | |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public Node getLastNode(){ |
| | | Node node = this.tail.pre ; |
| | | if(node != this.head){ |
| | | return node ; |
| | | //两个线程环境,需要同步锁 |
| | | synchronized(synObj) { |
| | | Node node = this.tail.pre; |
| | | if (node != this.head) { |
| | | return node; |
| | | } |
| | | return null; |
| | | } |
| | | return null ; |
| | | } |
| | | |
| | | /** |