project Version 0 |
|
👤 Author: by wuxian 2017-01-01 15:22:56 |
package question;
class ShareData{
//Use Char to represent the commodity
private char c;
//This variable is used to function as signal() in textbook.
private boolean putFlag = false;
//Use the reserved word synchronized to keep other process from run
//these following code when a process has entered into the putShareChar() method.
public synchronized void putShareChar(char c){
if(putFlag == true){
try{
wait();
}catch(InterruptedException e){}
}
this.c = c;
putFlag =