package com.cfqp;public class Phone {private static boolean flag = false;public static void main(String[] args) {Phone huaWei = new Phone();huaWei.run();}//手机开机了public void run() {//来电提醒线程new Thread(new Runnable() {@Overridepublic void run() {try {while (true) {synchronized (Phone.this) {if (!flag) {System.out.println("来电温馨提示,小朋友,有人呼叫你!");flag = true;Phone.this.notify();Phone.this.wait();}}}} catch (Exception e) {e.printStackTrace();}}}).start();//接听电话提new Thread(new Runnable() {@Overridepublic void run() {try {while(true){synchronized (Phone.this){if(flag){System.out.println("接听电话,我用了5分钟");Thread.sleep(5000);flag=false;Phone.this.notify();Phone.this.wait();}else{Phone.this.notify();Phone.this.wait();}}}} catch (Exception e) {e.printStackTrace();}}}).start();}}
700字范文,内容丰富有趣,生活中的好帮手!