zoukankan      html  css  js  c++  java
  • wait()方法写在while循环中可以在线程接到通知后再一次判断条件

    wait()方法写在while循环中可以在线程接到通知后再一次判断条件

    synchronized public String pop() {
            String returnValue = "";
            try {
                while(list.size()==0) {
                    System.out.println("pop操作中的:"+Thread.currentThread().getName()+" 线程呈wait状态");
                    this.wait(); // 这里wait()
                } // 接到notify()通知之后,还要走这段判断
                System.out.println("pop操作中的: "+Thread.currentThread().getName()+" 准备要remove了");
                returnValue = ""+list.get(0);
                list.remove(0);
                this.notify();
                System.out.println("pop="+list.size());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return returnValue;
        }
  • 相关阅读:
    RocketMQ简介
    redis简介
    netcat
    NOI2018 归程
    图论小专题B
    CF558E A Simple Task
    图论小专题A
    初等网络流初步
    2019炎德杯知识能力竞赛 游记
    POJ2176 Folding
  • 原文地址:https://www.cnblogs.com/stono/p/8449214.html
Copyright © 2011-2022 走看看