⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 produceconsumeaction.java

📁 JAVA网络编程电子书及源码
💻 JAVA
字号:
package multithread;

/**
 * 在这里插入类型说明。
 * 建立日期:(00-7-22 11:14:28)
 * @程序设计者:
 */
public class ProduceConsumeAction {
	private int common_stock;
	private boolean available_state=false;
/**
 * ProduceConsumeAction 构造子注释。
 */
public ProduceConsumeAction() {
	super();
}
/**
 * 在这里插入方法说明。
 * 建立日期:(00-7-22 11:31:16)
 */
public synchronized void consume_action(int who) {
	while (available_state==false){
		try{
			wait();
		}catch (InterruptedException e ){}
	}
	System.out.println("consumer"+who+"#:  "+common_stock);
	available_state=false;
	notify();
}
/**
 * 在这里插入方法说明。
 * 建立日期:(00-7-22 11:21:15)
 */
public synchronized void produce_action(int who,int product) {
	while (available_state==true ){
		try{
			wait();
		}catch (InterruptedException e ){}
	}
	common_stock=product;
	System.out.println(" produer"+who+"#:  "+common_stock);
	available_state=true;
	notify();

}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -