package com.huaao; public class Cooking { public void qiecai(){ synchronized (this) { System.out.println("正在切菜..."); try { this.wait(); chaocai(); } catch (InterruptedException e) { e.printStackTrace(); } } } public void shaoshui(){ synchronized (this) { System.out.println("正在烧水..."); try { this.wait(5000); System.out.println("水烧开了...可以炒菜了"); this.notify(); } catch (InterruptedException e) { e.printStackTrace(); } } } public void zhufan(){ System.out.println("正在煮饭..."); } public void chaocai(){ System.out.println("正在炒菜..."); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("抄完菜了,开吃..."); } public static void main(String[] args) { final Cooking cooking = new Cooking(); new Thread(new Runnable(){ @Override public void run() { cooking.shaoshui(); } }).start(); new Thread(new Runnable(){ @Override public void run() { cooking.zhufan(); } }).start(); new Thread(new Runnable(){ @Override public void run() { cooking.qiecai(); } }).start(); } }

telsawu LV1
2023年1月18日
我要赚钱 LV6
2020年11月4日
john93 LV15
2018年12月28日
dagf113225 LV68
2018年12月27日
刚睡醒的麋鹿 LV10
2018年4月2日
li74659526 LV2
2017年10月12日
maojianyun LV30
2017年8月19日
荭琪枫 LV15
2013年5月6日
aitixiaozi LV22
2013年3月23日
yihui1229 LV13
2013年3月21日