wait和notify的使用
来源:互联网 发布:macbook 安装软件 编辑:程序博客网 时间:2024/04/27 16:15
public class Food {
private int flag;
public void produce(){
synchronized (this) {
while(flag==0){
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("生产");
this.notifyAll();
flag=0;
}
}
public void coustem(){
synchronized (this) {
while(flag==1){
try {
this.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("消费");
this.notifyAll();
flag=1;
}
}
}
public class Produce extends Thread{
private Food food;
public Food getFood() {
return food;
}
public void setFood(Food food) {
this.food = food;
}
public void run(){
while(true){
food.produce();
}
}
}
package com.test;
public class Coustem extends Thread {
private Food food;
public Food getFood() {
return food;
}
public void setFood(Food food) {
this.food = food;
}
public void run(){
while(true){
food.coustem();
}
}
}
package com.test;
public class Test {
public static void main(String[] args) {
Food f= new Food();
Coustem c= new Coustem();
c.setFood(f);
Produce p = new Produce();
p.setFood(f);
c.start();
p.start();
}
}
- wait和notify的使用
- wait和notify的使用
- wait 和notify的使用
- wait和notify使用
- wait()和notify()的使用(来源于网络)
- Object的Wait() 和notify()方法使用
- wait和notify的理解与使用
- java wait和notify的使用
- java wait和notify的使用
- Java wait()和notify()的使用
- wait和notify的理解与使用
- wait和notify的理解与使用
- wait()/notify()的使用
- wait, notify 和 notifyAll 使用
- wait, notify, notifyAll的使用
- java的wait和notify
- java notify()和notifyall()的区别&wait()方法的使用
- Thread:线程之间的通信,使用wait()和notify()
- MyEclipse 10 下在线安装插件
- xcode 调试 只能选择iOS Device
- C库之basename
- 10大网站运营人员必备定律
- 云计算概念
- wait和notify的使用
- android 如何使用jni
- oracle 监听启动的时候 lsnrctl start 的显示 什么服务read unknown 之类的解释
- ExtJS是什么
- C库之cmd
- ProgressBar动画
- C++ list control基本使用
- 10件小事让你幸福至极
- 一枕落花香