题目内容

分析程序,写出结果class Info{private String name="张三";private boolean flag=false;public synchronized void set(String name){if(!flag){try {super.wait();} catch (InterruptedException e) {e.printStackTrace();}}this.setName(name);try {Thread.sleep(300);} catch (InterruptedException e) {e.printStackTrace();}flag=false;super.notify();}public synchronized void get(){if(flag){try {super.wait();} catch (InterruptedException e) {e.printStackTrace();}}try {Thread.sleep(300);} catch (InterruptedException e) {e.printStackTrace();}System.out.println(this.getName()+"-->" );flag=true;super.notify();}public String getName() {return name;}public void setName(String name) {this.name = name;}}class Producer implements Runnable{private Info info=null;public Producer(Info info){this.info=info;}@Overridepublic void run() {boolean flag=false;for(int i=0;i<20;i++){if(flag){this.info.set("张三");flag=false;}else{this.info.set("李四");flag=true;}}}}class Consumer implements Runnable{private Info info=null;public Consumer(Info info){this.info=info;}@Overridepublic void run() {for(int i=0;i<20;i++){try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}this.info.get();}}}public class ThreadDemo2 {public static void main(String[] args) {Info i=new Info();Producer pro=new Producer(i);Consumer con=new Consumer(i);new Thread(pro).start();new Thread(con).start();}}

查看答案
更多问题

制定幼儿语言教育目标的依据是什么?

幼儿语言教育目标是怎样划分结构的?

学前儿童语言教育的内容有哪些?

下列不属于学前阶段儿童倾听技能培养的是()

A. 有意识倾听
B. 辨析性倾听
C. 理解性倾听
D. 无意识倾听

答案查题题库